Codechange: Pass std::string_view from drivers instead of char *.
This commit is contained in:

committed by
Peter Nelson

parent
a42aa1a086
commit
332cbca36e
@@ -50,7 +50,7 @@ void SoundDriver_Allegro::MainLoop()
|
||||
*/
|
||||
extern int _allegro_instance_count;
|
||||
|
||||
const char *SoundDriver_Allegro::Start(const StringList &parm)
|
||||
std::optional<std::string_view> SoundDriver_Allegro::Start(const StringList &parm)
|
||||
{
|
||||
if (_allegro_instance_count == 0 && install_allegro(SYSTEM_AUTODETECT, &errno, nullptr)) {
|
||||
Debug(driver, 0, "allegro: install_allegro failed '{}'", allegro_error);
|
||||
@@ -74,7 +74,7 @@ const char *SoundDriver_Allegro::Start(const StringList &parm)
|
||||
_buffer_size = GetDriverParamInt(parm, "samples", 1024) * hz / 11025;
|
||||
_stream = play_audio_stream(_buffer_size, 16, true, hz, 255, 128);
|
||||
MxInitialize(hz);
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void SoundDriver_Allegro::Stop()
|
||||
|
@@ -15,12 +15,12 @@
|
||||
/** Implementation of the allegro sound driver. */
|
||||
class SoundDriver_Allegro : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const StringList ¶m) override;
|
||||
std::optional<std::string_view> Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
|
||||
void MainLoop() override;
|
||||
const char *GetName() const override { return "allegro"; }
|
||||
std::string_view GetName() const override { return "allegro"; }
|
||||
};
|
||||
|
||||
/** Factory for the allegro sound driver. */
|
||||
|
@@ -44,7 +44,7 @@ static OSStatus audioCallback(void *, AudioUnitRenderActionFlags *, const AudioT
|
||||
}
|
||||
|
||||
|
||||
const char *SoundDriver_Cocoa::Start(const StringList &parm)
|
||||
std::optional<std::string_view> SoundDriver_Cocoa::Start(const StringList &parm)
|
||||
{
|
||||
struct AURenderCallbackStruct callback;
|
||||
AudioStreamBasicDescription requestedDesc;
|
||||
@@ -108,7 +108,7 @@ const char *SoundDriver_Cocoa::Start(const StringList &parm)
|
||||
}
|
||||
|
||||
/* We're running! */
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
|
||||
|
@@ -14,10 +14,10 @@
|
||||
|
||||
class SoundDriver_Cocoa : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const StringList ¶m) override;
|
||||
std::optional<std::string_view> Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
const char *GetName() const override { return "cocoa"; }
|
||||
std::string_view GetName() const override { return "cocoa"; }
|
||||
};
|
||||
|
||||
class FSoundDriver_Cocoa : public DriverFactoryBase {
|
||||
|
@@ -15,10 +15,10 @@
|
||||
/** Implementation of the null sound driver. */
|
||||
class SoundDriver_Null : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const StringList &) override { return nullptr; }
|
||||
std::optional<std::string_view> Start(const StringList &) override { return std::nullopt; }
|
||||
|
||||
void Stop() override { }
|
||||
const char *GetName() const override { return "null"; }
|
||||
std::string_view GetName() const override { return "null"; }
|
||||
bool HasOutput() const override { return false; }
|
||||
};
|
||||
|
||||
|
@@ -30,7 +30,7 @@ static void CDECL fill_sound_buffer(void *, Uint8 *stream, int len)
|
||||
MxMixSamples(stream, len / 4);
|
||||
}
|
||||
|
||||
const char *SoundDriver_SDL::Start(const StringList &parm)
|
||||
std::optional<std::string_view> SoundDriver_SDL::Start(const StringList &parm)
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
SDL_AudioSpec spec_actual;
|
||||
@@ -52,7 +52,7 @@ const char *SoundDriver_SDL::Start(const StringList &parm)
|
||||
SDL_AudioDeviceID dev = SDL_OpenAudioDevice(nullptr, 0, &spec, &spec_actual, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
|
||||
MxInitialize(spec_actual.freq);
|
||||
SDL_PauseAudioDevice(dev, 0);
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void SoundDriver_SDL::Stop()
|
||||
|
@@ -30,7 +30,7 @@ static void CDECL fill_sound_buffer(void *, Uint8 *stream, int len)
|
||||
MxMixSamples(stream, len / 4);
|
||||
}
|
||||
|
||||
const char *SoundDriver_SDL::Start(const StringList &parm)
|
||||
std::optional<std::string_view> SoundDriver_SDL::Start(const StringList &parm)
|
||||
{
|
||||
SDL_AudioSpec spec;
|
||||
|
||||
@@ -51,7 +51,7 @@ const char *SoundDriver_SDL::Start(const StringList &parm)
|
||||
MxInitialize(spec.freq);
|
||||
SDL_OpenAudio(&spec, &spec);
|
||||
SDL_PauseAudio(0);
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void SoundDriver_SDL::Stop()
|
||||
|
@@ -15,10 +15,10 @@
|
||||
/** Implementation of the SDL sound driver. */
|
||||
class SoundDriver_SDL : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const StringList ¶m) override;
|
||||
std::optional<std::string_view> Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
const char *GetName() const override { return "sdl"; }
|
||||
std::string_view GetName() const override { return "sdl"; }
|
||||
};
|
||||
|
||||
/** Factory for the SDL sound driver. */
|
||||
|
@@ -59,7 +59,7 @@ static DWORD WINAPI SoundThread(LPVOID)
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *SoundDriver_Win32::Start(const StringList &parm)
|
||||
std::optional<std::string_view> SoundDriver_Win32::Start(const StringList &parm)
|
||||
{
|
||||
WAVEFORMATEX wfex;
|
||||
wfex.wFormatTag = WAVE_FORMAT_PCM;
|
||||
@@ -89,7 +89,7 @@ const char *SoundDriver_Win32::Start(const StringList &parm)
|
||||
return error;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
void SoundDriver_Win32::Stop()
|
||||
|
@@ -15,10 +15,10 @@
|
||||
/** Implementation of the sound driver for Windows. */
|
||||
class SoundDriver_Win32 : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const StringList ¶m) override;
|
||||
std::optional<std::string_view> Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
const char *GetName() const override { return "win32"; }
|
||||
std::string_view GetName() const override { return "win32"; }
|
||||
};
|
||||
|
||||
/** Factory for the sound driver for Windows. */
|
||||
|
@@ -135,10 +135,10 @@ static HRESULT CreateXAudio(API_XAudio2Create xAudio2Create)
|
||||
* Initialises the XAudio2 driver.
|
||||
*
|
||||
* @param parm Driver parameters.
|
||||
* @return An error message if unsuccessful, or nullptr otherwise.
|
||||
* @return An error message if unsuccessful, or std::nullopt otherwise.
|
||||
*
|
||||
*/
|
||||
const char *SoundDriver_XAudio2::Start(const StringList &parm)
|
||||
std::optional<std::string_view> SoundDriver_XAudio2::Start(const StringList &parm)
|
||||
{
|
||||
HRESULT hr = CoInitializeEx(nullptr, COINIT_MULTITHREADED);
|
||||
|
||||
@@ -257,7 +257,7 @@ const char *SoundDriver_XAudio2::Start(const StringList &parm)
|
||||
return "Failed to submit the first audio buffer";
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -15,10 +15,10 @@
|
||||
/** Implementation of the XAudio2 sound driver. */
|
||||
class SoundDriver_XAudio2 : public SoundDriver {
|
||||
public:
|
||||
const char *Start(const StringList ¶m) override;
|
||||
std::optional<std::string_view> Start(const StringList ¶m) override;
|
||||
|
||||
void Stop() override;
|
||||
const char *GetName() const override { return "xaudio2"; }
|
||||
std::string_view GetName() const override { return "xaudio2"; }
|
||||
};
|
||||
|
||||
/** Factory for the XAudio2 sound driver. */
|
||||
|
Reference in New Issue
Block a user