-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
149 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include <stdexcept> | ||
#include "SdlAudioOutput.h" | ||
|
||
namespace sdl { | ||
|
||
SdlAudioOutput::SdlAudioOutput() { | ||
|
||
if (SDL_AudioInit(nullptr) != 0) { | ||
throw std::runtime_error(SDL_GetError()); | ||
} | ||
} | ||
|
||
void SdlAudioOutput::initialiseAudio() { | ||
SDL_AudioSpec want, have; | ||
|
||
SDL_memset(&want, 0, sizeof(want)); | ||
want.freq = 48000; | ||
want.format = AUDIO_S16LSB; | ||
want.channels = 2; | ||
want.samples = 1024; | ||
want.callback = nullptr; | ||
_audio = SDL_OpenAudioDevice(nullptr, 0, &want, &have, SDL_AUDIO_ALLOW_FORMAT_CHANGE); | ||
SDL_PauseAudioDevice(_audio, 0); | ||
} | ||
|
||
void SdlAudioOutput::audioFrameAvailable(uint32_t *audio) { | ||
SDL_QueueAudio(_audio, audio, 800 * 4); | ||
} | ||
|
||
void SdlAudioOutput::render() { | ||
// Should be where audio data is written to the audio pipe | ||
} | ||
|
||
void SdlAudioOutput::shutdownAudio() { | ||
SDL_PauseAudioDevice(_audio, 1); | ||
SDL_CloseAudioDevice(_audio); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef LGX2USERSPACE_SDLAUDIOOUTPUT_H | ||
#define LGX2USERSPACE_SDLAUDIOOUTPUT_H | ||
|
||
#include "lgxdevice.h" | ||
#include <SDL2/SDL.h> | ||
|
||
namespace sdl { | ||
class SdlAudioOutput : public lgx2::AudioOutput { | ||
public: | ||
SdlAudioOutput(); | ||
|
||
void initialiseAudio() override; | ||
|
||
void audioFrameAvailable(uint32_t *audio) override; | ||
|
||
void render() override; | ||
|
||
void shutdownAudio() override; | ||
private: | ||
SDL_AudioDeviceID _audio{}; | ||
}; | ||
} | ||
|
||
|
||
#endif //LGX2USERSPACE_SDLAUDIOOUTPUT_H |
Oops, something went wrong.