<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          libsoundio跨平臺(tái)實(shí)時(shí)音頻驅(qū)動(dòng)

          聯(lián)合創(chuàng)作 · 2023-09-29 20:22

          libsoundio 是輕量級(jí)抽象的聲音驅(qū)動(dòng)程序,是一個(gè)跨平臺(tái)實(shí)時(shí)音頻輸入和輸出的 C99 庫(kù)。libsoundio 提供文檔完善的 API,適用于實(shí)時(shí)軟件,比如游戲,數(shù)字音頻工作站,音樂(lè)播放器等等實(shí)用工具。

          libsoundio 非常健壯,可以正確處理內(nèi)存不足的狀態(tài)。

          特性&限制

          • 支持的后端

          • 支持原始設(shè)備和共享設(shè)備

          • 支持設(shè)備 ID 和友好的名字

          • 支持優(yōu)化每個(gè)后端的使用

          • C 語(yǔ)言庫(kù),僅僅依賴于后端 API 庫(kù)和 libc


          • 支持頻道布局

          基礎(chǔ)正弦波示例

          #include <soundio/soundio.h>
          #include <stdio.h>
          #include <stdlib.h>
          #include <string.h>
          #include <math.h>
          static const float PI = 3.1415926535f;
          static float seconds_offset = 0.0f;
          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 seconds_per_frame = 1.0f / float_sample_rate;
              struct SoundIoChannelArea *areas;
              int frames_left = frame_count_max;
              int err;
              while (frames_left > 0) {
                  int frame_count = frames_left;
                  if ((err = soundio_outstream_begin_write(outstream, &areas, &frame_count))) {
                      fprintf(stderr, "%s\n", soundio_strerror(err));
                      exit(1);
                  }
                  if (!frame_count)
                      break;
                  float pitch = 440.0f;
                  float radians_per_second = pitch * 2.0f * PI;
                  for (int frame = 0; frame < frame_count; frame += 1) {
                      float sample = sinf((seconds_offset + frame * seconds_per_frame) * radians_per_second);
                      for (int channel = 0; channel < layout->channel_count; channel += 1) {
                          float *ptr = (float*)(areas[channel].ptr + areas[channel].step * frame);
                          *ptr = sample;
                      }
                  }
                  seconds_offset += seconds_per_frame * frame_count;
                  if ((err = soundio_outstream_end_write(outstream))) {
                      fprintf(stderr, "%s\n", soundio_strerror(err));
                      exit(1);
                  }
                  frames_left -= frame_count;
              }
          }
          int main(int argc, char **argv) {
              int err;
              struct SoundIo *soundio = soundio_create();
              if (!soundio) {
                  fprintf(stderr, "out of memory\n");
                  return 1;
              }
              if ((err = soundio_connect(soundio))) {
                  fprintf(stderr, "error connecting: %s", soundio_strerror(err));
                  return 1;
              }
              soundio_flush_events(soundio);
              int default_out_device_index = soundio_default_output_device_index(soundio);
              if (default_out_device_index < 0) {
                  fprintf(stderr, "no output device found");
                  return 1;
              }
              struct SoundIoDevice *device = soundio_get_output_device(soundio, default_out_device_index);
              if (!device) {
                  fprintf(stderr, "out of memory");
                  return 1;
              }
              fprintf(stderr, "Output device: %s\n", device->name);
              struct SoundIoOutStream *outstream = soundio_outstream_create(device);
              outstream->format = SoundIoFormatFloat32NE;
              outstream->write_callback = write_callback;
              if ((err = soundio_outstream_open(outstream))) {
                  fprintf(stderr, "unable to open device: %s", soundio_strerror(err));
                  return 1;
              }
              if (outstream->layout_error)
                  fprintf(stderr, "unable to set channel layout: %s\n", soundio_strerror(outstream->layout_error));
              if ((err = soundio_outstream_start(outstream))) {
                  fprintf(stderr, "unable to start device: %s", soundio_strerror(err));
                  return 1;
              }
              for (;;)
                  soundio_wait_events(soundio);
              soundio_outstream_destroy(outstream);
              soundio_device_unref(device);
              soundio_destroy(soundio);
              return 0;
          }
          瀏覽 25
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          評(píng)論
          圖片
          表情
          推薦
          點(diǎn)贊
          評(píng)論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報(bào)
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  97色网站在线观看免费视频 | 国产夫妻自拍网 | 亚洲免费一级 | 色日本黄网站 | 韩国久久 |