/[svn]/linuxsampler/trunk/src/audioio.cpp
ViewVC logotype

Diff of /linuxsampler/trunk/src/audioio.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 13 by schoenebeck, Fri Nov 21 15:07:23 2003 UTC revision 28 by schoenebeck, Fri Jan 2 00:02:56 2004 UTC
# Line 79  int AudioIO::Initialize(uint channels, u Line 79  int AudioIO::Initialize(uint channels, u
79      }      }
80    
81      /* Set sample format */      /* Set sample format */
82        #if WORDS_BIGENDIAN
83        if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_BE)) < 0) {
84        #else // little endian
85      if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE)) < 0) {      if ((err = snd_pcm_hw_params_set_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE)) < 0) {
86        #endif
87          fprintf(stderr, "Error setting sample format. : %s\n", snd_strerror(err));          fprintf(stderr, "Error setting sample format. : %s\n", snd_strerror(err));
88          return EXIT_FAILURE;          return EXIT_FAILURE;
89      }      }
90    
91        int dir = 0;
92    
93      /* Set sample rate. If the exact rate is not supported */      /* Set sample rate. If the exact rate is not supported */
94      /* by the hardware, use nearest possible rate.         */      /* by the hardware, use nearest possible rate.         */
95      if((err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, samplerate, 0)) < 0) {      #if ALSA_MAJOR > 0
96        if((err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, &samplerate, &dir)) < 0) {
97        #else
98        if((err = snd_pcm_hw_params_set_rate_near(pcm_handle, hwparams, samplerate, &dir)) < 0) {
99        #endif
100          fprintf(stderr, "Error setting sample rate. : %s\n", snd_strerror(err));          fprintf(stderr, "Error setting sample rate. : %s\n", snd_strerror(err));
101          return EXIT_FAILURE;          return EXIT_FAILURE;
102      }      }
# Line 97  int AudioIO::Initialize(uint channels, u Line 107  int AudioIO::Initialize(uint channels, u
107      }      }
108    
109      /* Set number of periods. Periods used to be called fragments. */      /* Set number of periods. Periods used to be called fragments. */
110      if ((err = snd_pcm_hw_params_set_periods(pcm_handle, hwparams, numfragments, 0)) < 0) {      if ((err = snd_pcm_hw_params_set_periods(pcm_handle, hwparams, numfragments, dir)) < 0) {
111          fprintf(stderr, "Error setting number of periods. : %s\n", snd_strerror(err));          fprintf(stderr, "Error setting number of periods. : %s\n", snd_strerror(err));
112          return EXIT_FAILURE;          return EXIT_FAILURE;
113      }      }
# Line 166  bool AudioIO::HardwareParametersSupporte Line 176  bool AudioIO::HardwareParametersSupporte
176          snd_pcm_close(pcm_handle);          snd_pcm_close(pcm_handle);
177          return false;          return false;
178      }      }
179        #if WORDS_BIGENDIAN
180        if (snd_pcm_hw_params_test_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_BE) < 0) {
181        #else // little endian
182      if (snd_pcm_hw_params_test_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE) < 0) {      if (snd_pcm_hw_params_test_format(pcm_handle, hwparams, SND_PCM_FORMAT_S16_LE) < 0) {
183        #endif
184          snd_pcm_close(pcm_handle);          snd_pcm_close(pcm_handle);
185          return false;          return false;
186      }      }
187      if (snd_pcm_hw_params_test_rate(pcm_handle, hwparams, samplerate, 0) < 0) {      int dir = 0;
188        if (snd_pcm_hw_params_test_rate(pcm_handle, hwparams, samplerate, dir) < 0) {
189          snd_pcm_close(pcm_handle);          snd_pcm_close(pcm_handle);
190          return false;          return false;
191      }      }
# Line 178  bool AudioIO::HardwareParametersSupporte Line 193  bool AudioIO::HardwareParametersSupporte
193          snd_pcm_close(pcm_handle);          snd_pcm_close(pcm_handle);
194          return false;          return false;
195      }      }
196      if (snd_pcm_hw_params_test_periods(pcm_handle, hwparams, numfragments, 0) < 0) {      if (snd_pcm_hw_params_test_periods(pcm_handle, hwparams, numfragments, dir) < 0) {
197          snd_pcm_close(pcm_handle);          snd_pcm_close(pcm_handle);
198          return false;          return false;
199      }      }
# Line 191  bool AudioIO::HardwareParametersSupporte Line 206  bool AudioIO::HardwareParametersSupporte
206      return true;      return true;
207  }  }
208    
209    /**
210     *  Will be called by the audio engine after every audio fragment cycle, to
211     *  output the audio data of the current fragment to the soundcard.
212     *
213     *  @returns  0 on success
214     */
215  int AudioIO::Output() {  int AudioIO::Output() {
216      int err = snd_pcm_writei(pcm_handle, pOutputBuffer, FragmentSize);      int err = snd_pcm_writei(pcm_handle, pOutputBuffer, FragmentSize);
217      if (err < 0) {      if (err < 0) {

Legend:
Removed from v.13  
changed lines
  Added in v.28

  ViewVC Help
Powered by ViewVC