mirror of
https://github.com/Ryujinx/libsoundio.git
synced 2025-01-03 15:25:42 +00:00
README: fix synopsis example
This commit is contained in:
parent
c381526205
commit
a6c5f99b27
27
README.md
27
README.md
|
@ -75,23 +75,25 @@ static void panic(const char *format, ...) {
|
||||||
|
|
||||||
static const float PI = 3.1415926535f;
|
static const float PI = 3.1415926535f;
|
||||||
static float seconds_offset = 0.0f;
|
static float seconds_offset = 0.0f;
|
||||||
static void write_callback(struct SoundIoOutStream *outstream, int requested_frame_count) {
|
static void write_callback(struct SoundIoOutStream *outstream,
|
||||||
|
int frame_count_min, int frame_count_max)
|
||||||
|
{
|
||||||
|
const struct SoundIoChannelLayout *layout = &outstream->layout;
|
||||||
float float_sample_rate = outstream->sample_rate;
|
float float_sample_rate = outstream->sample_rate;
|
||||||
float seconds_per_frame = 1.0f / float_sample_rate;
|
float seconds_per_frame = 1.0f / float_sample_rate;
|
||||||
|
struct SoundIoChannelArea *areas;
|
||||||
|
int frames_left = frame_count_max;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
for (;;) {
|
while (frames_left > 0) {
|
||||||
int frame_count = requested_frame_count;
|
int frame_count = frames_left;
|
||||||
|
|
||||||
struct SoundIoChannelArea *areas;
|
|
||||||
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count)))
|
if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count)))
|
||||||
panic("%s", soundio_strerror(err));
|
panic("%s", soundio_strerror(err));
|
||||||
|
|
||||||
if (!frame_count)
|
if (!frame_count)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
const struct SoundIoChannelLayout *layout = &outstream->layout;
|
|
||||||
|
|
||||||
float pitch = 440.0f;
|
float pitch = 440.0f;
|
||||||
float radians_per_second = pitch * 2.0f * PI;
|
float radians_per_second = pitch * 2.0f * PI;
|
||||||
for (int frame = 0; frame < frame_count; frame += 1) {
|
for (int frame = 0; frame < frame_count; frame += 1) {
|
||||||
|
@ -103,16 +105,15 @@ static void write_callback(struct SoundIoOutStream *outstream, int requested_fra
|
||||||
}
|
}
|
||||||
seconds_offset += seconds_per_frame * frame_count;
|
seconds_offset += seconds_per_frame * frame_count;
|
||||||
|
|
||||||
if ((err = soundio_outstream_end_write(outstream, frame_count)))
|
if ((err = soundio_outstream_end_write(outstream)))
|
||||||
panic("%s", soundio_strerror(err));
|
panic("%s", soundio_strerror(err));
|
||||||
|
|
||||||
requested_frame_count -= frame_count;
|
frames_left -= frame_count;
|
||||||
if (requested_frame_count <= 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
int err;
|
||||||
struct SoundIo *soundio = soundio_create();
|
struct SoundIo *soundio = soundio_create();
|
||||||
if (!soundio)
|
if (!soundio)
|
||||||
panic("out of memory");
|
panic("out of memory");
|
||||||
|
@ -120,7 +121,9 @@ int main(int argc, char **argv) {
|
||||||
if ((err = soundio_connect(soundio)))
|
if ((err = soundio_connect(soundio)))
|
||||||
panic("error connecting: %s", soundio_strerror(err));
|
panic("error connecting: %s", soundio_strerror(err));
|
||||||
|
|
||||||
int default_out_device_index = soundio_get_default_output_device_index(soundio);
|
soundio_flush_events(soundio);
|
||||||
|
|
||||||
|
int default_out_device_index = soundio_default_output_device_index(soundio);
|
||||||
if (default_out_device_index < 0)
|
if (default_out_device_index < 0)
|
||||||
panic("no output device found");
|
panic("no output device found");
|
||||||
|
|
||||||
|
@ -128,7 +131,7 @@ int main(int argc, char **argv) {
|
||||||
if (!device)
|
if (!device)
|
||||||
panic("out of memory");
|
panic("out of memory");
|
||||||
|
|
||||||
fprintf(stderr, "Output device: %s: %s\n", device->name, device->description);
|
fprintf(stderr, "Output device: %s\n", device->name);
|
||||||
|
|
||||||
struct SoundIoOutStream *outstream = soundio_outstream_create(device);
|
struct SoundIoOutStream *outstream = soundio_outstream_create(device);
|
||||||
outstream->format = SoundIoFormatFloat32NE;
|
outstream->format = SoundIoFormatFloat32NE;
|
||||||
|
|
Loading…
Reference in a new issue