-
Notifications
You must be signed in to change notification settings - Fork 465
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
100 changed files
with
21,929 additions
and
97 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
/*****************************************************************************\ | ||
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. | ||
This file is licensed under the Snes9x License. | ||
For further information, consult the LICENSE file in the root directory. | ||
\*****************************************************************************/ | ||
|
||
#include "s9x_sound_driver_cubeb.hpp" | ||
#include <cstdio> | ||
|
||
void S9xCubebSoundDriver::write_samples(int16_t *data, int samples) | ||
{ | ||
if (samples > buffer.space_empty()) | ||
samples = buffer.space_empty(); | ||
buffer.push(data, samples); | ||
} | ||
|
||
S9xCubebSoundDriver::S9xCubebSoundDriver() | ||
{ | ||
} | ||
|
||
S9xCubebSoundDriver::~S9xCubebSoundDriver() | ||
{ | ||
deinit(); | ||
} | ||
|
||
void S9xCubebSoundDriver::init() | ||
{ | ||
if (!context) | ||
cubeb_init(&context, "Snes9x", nullptr); | ||
stop(); | ||
} | ||
|
||
void S9xCubebSoundDriver::deinit() | ||
{ | ||
stop(); | ||
if (stream) | ||
{ | ||
cubeb_stream_destroy(stream); | ||
stream = nullptr; | ||
} | ||
|
||
if (context) | ||
{ | ||
cubeb_destroy(context); | ||
context = nullptr; | ||
} | ||
} | ||
|
||
void S9xCubebSoundDriver::start() | ||
{ | ||
if (stream) | ||
cubeb_stream_start(stream); | ||
} | ||
|
||
void S9xCubebSoundDriver::stop() | ||
{ | ||
if (stream) | ||
cubeb_stream_stop(stream); | ||
} | ||
|
||
void state_callback(cubeb_stream *stream, void *user_ptr, cubeb_state state) | ||
{ | ||
} | ||
|
||
long data_callback(cubeb_stream *stream, void *user_ptr, | ||
void const *input_buffer, | ||
void *output_buffer, long nframes) | ||
{ | ||
return ((S9xCubebSoundDriver *)user_ptr)->data_callback(stream, input_buffer, output_buffer, nframes); | ||
} | ||
|
||
long S9xCubebSoundDriver::data_callback(cubeb_stream *stream, void const *input_buffer, void *output_buffer, long nframes) | ||
{ | ||
buffer.read((int16_t *)output_buffer, nframes * 2); | ||
return nframes; | ||
} | ||
|
||
bool S9xCubebSoundDriver::open_device(int playback_rate, int buffer_size) | ||
{ | ||
cubeb_stream_params params{}; | ||
params.channels = 2; | ||
params.format = CUBEB_SAMPLE_S16LE; | ||
params.layout = CUBEB_LAYOUT_UNDEFINED; | ||
params.rate = playback_rate; | ||
params.prefs = CUBEB_STREAM_PREF_NONE; | ||
|
||
uint32_t min_latency; | ||
cubeb_get_min_latency(context, ¶ms, &min_latency); | ||
|
||
auto retval = cubeb_stream_init(context, &stream, "Snes9x", | ||
nullptr, nullptr, | ||
nullptr, ¶ms, | ||
min_latency, | ||
&::data_callback, | ||
&state_callback, | ||
this); | ||
|
||
if (retval != CUBEB_OK) | ||
{ | ||
printf("Failed to start stream. Error: %d!\n", retval); | ||
stream = nullptr; | ||
return false; | ||
} | ||
|
||
buffer.resize(2 * buffer_size * playback_rate / 1000); | ||
|
||
return true; | ||
} | ||
|
||
int S9xCubebSoundDriver::space_free() | ||
{ | ||
return buffer.space_empty(); | ||
} | ||
|
||
std::pair<int, int> S9xCubebSoundDriver::buffer_level() | ||
{ | ||
return { buffer.space_empty(), buffer.buffer_size }; | ||
} |
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,36 @@ | ||
/*****************************************************************************\ | ||
Snes9x - Portable Super Nintendo Entertainment System (TM) emulator. | ||
This file is licensed under the Snes9x License. | ||
For further information, consult the LICENSE file in the root directory. | ||
\*****************************************************************************/ | ||
|
||
#ifndef __S9X_SOUND_DRIVER_CUBEB_HPP | ||
#define __S9X_SOUND_DRIVER_CUBEB_HPP | ||
|
||
#include "s9x_sound_driver.hpp" | ||
#include <cstdint> | ||
#include "cubeb/cubeb.h" | ||
#include "../../apu/resampler.h" | ||
|
||
class S9xCubebSoundDriver : public S9xSoundDriver | ||
{ | ||
public: | ||
S9xCubebSoundDriver(); | ||
~S9xCubebSoundDriver(); | ||
void init() override; | ||
void deinit() override; | ||
bool open_device(int playback_rate, int buffer_size) override; | ||
void start() override; | ||
void stop() override; | ||
long data_callback(cubeb_stream *stream, void const *input_buffer, void *output_buffer, long nframes); | ||
void write_samples(int16_t *data, int samples) override; | ||
int space_free() override; | ||
std::pair<int, int> buffer_level() override; | ||
|
||
private: | ||
Resampler buffer; | ||
cubeb *context = nullptr; | ||
cubeb_stream *stream = nullptr; | ||
}; | ||
|
||
#endif /* __S9X_SOUND_DRIVER_SDL_HPP */ |
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 |
---|---|---|
|
@@ -94,6 +94,8 @@ bool GTKGLXContext::create_context() | |
return false; | ||
} | ||
|
||
resize(); | ||
|
||
return true; | ||
} | ||
|
||
|
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
Oops, something went wrong.