2006-01-09 11:22:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 by Nick Lanham
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "autoconf.h"
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
2006-02-13 21:46:28 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <memory.h>
|
2006-03-11 10:22:20 +00:00
|
|
|
#include "debug.h"
|
2006-02-23 21:13:03 +00:00
|
|
|
#include "kernel.h"
|
2006-01-09 11:22:36 +00:00
|
|
|
#include "sound.h"
|
2007-05-04 15:39:01 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
#ifndef REC_SAMPR_CAPS
|
|
|
|
#define REC_SAMPR_CAPS SAMPR_CAP_44
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
#include "pcm_sampr.h"
|
2006-02-13 21:46:28 +00:00
|
|
|
#include "SDL.h"
|
|
|
|
|
|
|
|
static bool pcm_playing;
|
|
|
|
static bool pcm_paused;
|
2007-05-04 15:14:56 +00:00
|
|
|
static int cvt_status = -1;
|
|
|
|
static unsigned long pcm_frequency = SAMPR_44;
|
|
|
|
static unsigned long pcm_curr_frequency = SAMPR_44;
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
static Uint8* pcm_data;
|
2006-03-22 16:04:01 +00:00
|
|
|
static size_t pcm_data_size;
|
2007-05-04 15:14:56 +00:00
|
|
|
static size_t pcm_sample_bytes;
|
|
|
|
static size_t pcm_channel_bytes;
|
|
|
|
|
|
|
|
struct pcm_udata
|
|
|
|
{
|
|
|
|
Uint8 *stream;
|
|
|
|
Uint32 num_in;
|
|
|
|
Uint32 num_out;
|
|
|
|
FILE *debug;
|
|
|
|
} udata;
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2007-01-05 10:30:18 +00:00
|
|
|
static SDL_AudioSpec obtained;
|
|
|
|
static SDL_AudioCVT cvt;
|
|
|
|
|
2006-02-21 21:48:06 +00:00
|
|
|
extern bool debug_audio;
|
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void pcm_apply_settings_nolock(void)
|
2006-01-09 11:22:36 +00:00
|
|
|
{
|
2007-05-04 15:14:56 +00:00
|
|
|
cvt_status = SDL_BuildAudioCVT(&cvt, AUDIO_S16SYS, 2, pcm_frequency,
|
|
|
|
obtained.format, obtained.channels, obtained.freq);
|
|
|
|
|
|
|
|
pcm_curr_frequency = pcm_frequency;
|
|
|
|
|
|
|
|
if (cvt_status < 0) {
|
|
|
|
cvt.len_ratio = (double)obtained.freq / (double)pcm_curr_frequency;
|
|
|
|
}
|
|
|
|
}
|
2006-02-13 21:46:28 +00:00
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
void pcm_apply_settings(void)
|
|
|
|
{
|
2006-02-21 21:48:06 +00:00
|
|
|
SDL_LockAudio();
|
2007-05-04 15:14:56 +00:00
|
|
|
pcm_apply_settings_nolock();
|
|
|
|
SDL_UnlockAudio();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void sdl_dma_start_nolock(const void *addr, size_t size)
|
|
|
|
{
|
|
|
|
pcm_playing = false;
|
|
|
|
|
|
|
|
pcm_apply_settings_nolock();
|
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
pcm_data = (Uint8 *) addr;
|
|
|
|
pcm_data_size = size;
|
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
pcm_playing = true;
|
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
SDL_PauseAudio(0);
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
static void sdl_dma_stop_nolock(void)
|
2006-01-09 11:22:36 +00:00
|
|
|
{
|
2006-02-13 21:46:28 +00:00
|
|
|
pcm_playing = false;
|
|
|
|
|
|
|
|
SDL_PauseAudio(1);
|
|
|
|
|
|
|
|
pcm_paused = false;
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
static void (*callback_for_more)(unsigned char**, size_t*) = NULL;
|
|
|
|
void pcm_play_data(void (*get_more)(unsigned char** start, size_t* size),
|
|
|
|
unsigned char* start, size_t size)
|
2006-01-09 11:22:36 +00:00
|
|
|
{
|
2007-05-04 15:14:56 +00:00
|
|
|
SDL_LockAudio();
|
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
callback_for_more = get_more;
|
|
|
|
|
|
|
|
if (!(start && size)) {
|
|
|
|
if (get_more)
|
|
|
|
get_more(&start, &size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (start && size) {
|
2007-05-04 15:14:56 +00:00
|
|
|
sdl_dma_start_nolock(start, size);
|
2006-02-13 21:46:28 +00:00
|
|
|
}
|
2007-05-04 15:14:56 +00:00
|
|
|
|
|
|
|
SDL_UnlockAudio();
|
2006-02-13 21:46:28 +00:00
|
|
|
}
|
2006-01-09 11:22:36 +00:00
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
size_t pcm_get_bytes_waiting(void)
|
|
|
|
{
|
|
|
|
return pcm_data_size;
|
|
|
|
}
|
2006-01-13 13:38:31 +00:00
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
void pcm_mute(bool mute)
|
|
|
|
{
|
|
|
|
(void) mute;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_play_stop(void)
|
|
|
|
{
|
2007-05-04 15:14:56 +00:00
|
|
|
SDL_LockAudio();
|
2006-02-13 21:46:28 +00:00
|
|
|
if (pcm_playing) {
|
2007-05-04 15:14:56 +00:00
|
|
|
sdl_dma_stop_nolock();
|
2006-02-13 21:46:28 +00:00
|
|
|
}
|
2007-05-04 15:14:56 +00:00
|
|
|
SDL_UnlockAudio();
|
2006-02-13 21:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_play_pause(bool play)
|
|
|
|
{
|
2006-03-22 16:04:01 +00:00
|
|
|
size_t next_size;
|
2006-02-13 21:46:28 +00:00
|
|
|
Uint8 *next_start;
|
2007-05-04 15:14:56 +00:00
|
|
|
|
|
|
|
SDL_LockAudio();
|
2006-02-13 21:46:28 +00:00
|
|
|
|
|
|
|
if (!pcm_playing) {
|
2007-05-04 15:14:56 +00:00
|
|
|
SDL_UnlockAudio();
|
2006-02-13 21:46:28 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pcm_paused && play) {
|
|
|
|
if (pcm_get_bytes_waiting()) {
|
|
|
|
printf("unpause\n");
|
2007-05-04 15:14:56 +00:00
|
|
|
pcm_apply_settings_nolock();
|
2006-02-13 21:46:28 +00:00
|
|
|
SDL_PauseAudio(0);
|
|
|
|
} else {
|
|
|
|
printf("unpause, no data waiting\n");
|
|
|
|
|
|
|
|
void (*get_more)(unsigned char**, size_t*) = callback_for_more;
|
|
|
|
|
|
|
|
if (get_more) {
|
|
|
|
get_more(&next_start, &next_size);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next_start && next_size) {
|
2007-05-04 15:14:56 +00:00
|
|
|
sdl_dma_start_nolock(next_start, next_size);
|
2006-02-13 21:46:28 +00:00
|
|
|
} else {
|
2007-05-04 15:14:56 +00:00
|
|
|
sdl_dma_stop_nolock();
|
2006-02-13 21:46:28 +00:00
|
|
|
printf("unpause attempted, no data\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if(!pcm_paused && !play) {
|
|
|
|
printf("pause\n");
|
|
|
|
|
|
|
|
SDL_PauseAudio(1);
|
|
|
|
}
|
2006-02-22 22:45:10 +00:00
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
pcm_paused = !play;
|
2007-05-04 15:14:56 +00:00
|
|
|
|
|
|
|
SDL_UnlockAudio();
|
2006-02-13 21:46:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool pcm_is_paused(void)
|
|
|
|
{
|
|
|
|
return pcm_paused;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool pcm_is_playing(void)
|
|
|
|
{
|
|
|
|
return pcm_playing;
|
|
|
|
}
|
|
|
|
|
2007-01-01 14:01:08 +00:00
|
|
|
void pcm_set_frequency(unsigned int frequency)
|
|
|
|
{
|
2007-05-04 15:14:56 +00:00
|
|
|
switch (frequency)
|
|
|
|
{
|
|
|
|
HW_HAVE_8_( case SAMPR_8:)
|
|
|
|
HW_HAVE_11_(case SAMPR_11:)
|
|
|
|
HW_HAVE_12_(case SAMPR_12:)
|
|
|
|
HW_HAVE_16_(case SAMPR_16:)
|
|
|
|
HW_HAVE_22_(case SAMPR_22:)
|
|
|
|
HW_HAVE_24_(case SAMPR_24:)
|
|
|
|
HW_HAVE_32_(case SAMPR_32:)
|
2007-05-04 15:39:01 +00:00
|
|
|
HW_HAVE_44_(case SAMPR_44:)
|
2007-05-04 15:14:56 +00:00
|
|
|
HW_HAVE_48_(case SAMPR_48:)
|
|
|
|
HW_HAVE_64_(case SAMPR_64:)
|
|
|
|
HW_HAVE_88_(case SAMPR_88:)
|
|
|
|
HW_HAVE_96_(case SAMPR_96:)
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
frequency = SAMPR_44;
|
|
|
|
}
|
|
|
|
|
|
|
|
pcm_frequency = frequency;
|
2007-01-01 14:01:08 +00:00
|
|
|
}
|
|
|
|
|
2006-02-23 21:13:03 +00:00
|
|
|
/*
|
|
|
|
* This function goes directly into the DMA buffer to calculate the left and
|
|
|
|
* right peak values. To avoid missing peaks it tries to look forward two full
|
|
|
|
* peek periods (2/HZ sec, 100% overlap), although it's always possible that
|
|
|
|
* the entire period will not be visible. To reduce CPU load it only looks at
|
|
|
|
* every third sample, and this can be reduced even further if needed (even
|
|
|
|
* every tenth sample would still be pretty accurate).
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define PEAK_SAMPLES (44100*2/HZ) /* 44100 samples * 2 / 100 Hz tick */
|
|
|
|
#define PEAK_STRIDE 3 /* every 3rd sample is plenty... */
|
|
|
|
|
|
|
|
void pcm_calculate_peaks(int *left, int *right)
|
|
|
|
{
|
2006-02-23 21:42:53 +00:00
|
|
|
long samples = (long) pcm_data_size / 4;
|
|
|
|
short *addr = (short *) pcm_data;
|
2006-02-23 21:13:03 +00:00
|
|
|
|
|
|
|
if (samples > PEAK_SAMPLES)
|
|
|
|
samples = PEAK_SAMPLES;
|
|
|
|
|
|
|
|
samples /= PEAK_STRIDE;
|
|
|
|
|
|
|
|
if (left && right) {
|
|
|
|
int left_peak = 0, right_peak = 0, value;
|
|
|
|
|
|
|
|
while (samples--) {
|
|
|
|
if ((value = addr [0]) > left_peak)
|
|
|
|
left_peak = value;
|
|
|
|
else if (-value > left_peak)
|
|
|
|
left_peak = -value;
|
|
|
|
|
|
|
|
if ((value = addr [PEAK_STRIDE | 1]) > right_peak)
|
|
|
|
right_peak = value;
|
|
|
|
else if (-value > right_peak)
|
|
|
|
right_peak = -value;
|
|
|
|
|
|
|
|
addr += PEAK_STRIDE * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
*left = left_peak;
|
|
|
|
*right = right_peak;
|
|
|
|
}
|
|
|
|
else if (left || right) {
|
|
|
|
int peak_value = 0, value;
|
|
|
|
|
|
|
|
if (right)
|
|
|
|
addr += (PEAK_STRIDE | 1);
|
|
|
|
|
|
|
|
while (samples--) {
|
|
|
|
if ((value = addr [0]) > peak_value)
|
|
|
|
peak_value = value;
|
|
|
|
else if (-value > peak_value)
|
|
|
|
peak_value = -value;
|
|
|
|
|
|
|
|
addr += PEAK_STRIDE * 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (left)
|
|
|
|
*left = peak_value;
|
|
|
|
else
|
|
|
|
*right = peak_value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-31 11:41:42 +00:00
|
|
|
extern int sim_volume; /* in firmware/sound.c
|
2007-05-04 15:14:56 +00:00
|
|
|
void write_to_soundcard(struct pcm_udata *udata) {
|
2007-01-05 10:30:18 +00:00
|
|
|
if (cvt.needed) {
|
2007-05-04 15:14:56 +00:00
|
|
|
Uint32 rd = udata->num_in;
|
|
|
|
Uint32 wr = (double)rd * cvt.len_ratio;
|
2007-01-05 10:30:18 +00:00
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
if (wr > udata->num_out) {
|
|
|
|
wr = udata->num_out;
|
|
|
|
rd = (double)wr / cvt.len_ratio;
|
2007-01-05 10:30:18 +00:00
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
if (rd > udata->num_in)
|
|
|
|
{
|
|
|
|
rd = udata->num_in;
|
|
|
|
wr = (double)rd * cvt.len_ratio;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wr == 0 || rd == 0)
|
|
|
|
{
|
|
|
|
udata->num_out = udata->num_in = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cvt_status > 0) {
|
|
|
|
cvt.len = rd * pcm_sample_bytes;
|
|
|
|
cvt.buf = (Uint8 *) malloc(cvt.len * cvt.len_mult);
|
|
|
|
|
|
|
|
memcpy(cvt.buf, pcm_data, cvt.len);
|
|
|
|
|
|
|
|
SDL_ConvertAudio(&cvt);
|
2007-07-31 11:41:42 +00:00
|
|
|
SDL_MixAudio(udata->stream, cvt.buf, cvt.len_cvt, sim_volume);
|
2007-05-04 15:14:56 +00:00
|
|
|
|
|
|
|
udata->num_in = cvt.len / pcm_sample_bytes;
|
|
|
|
udata->num_out = cvt.len_cvt / pcm_sample_bytes;
|
|
|
|
|
|
|
|
if (udata->debug != NULL) {
|
|
|
|
fwrite(cvt.buf, sizeof(Uint8), cvt.len_cvt, udata->debug);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(cvt.buf);
|
2007-01-05 10:30:18 +00:00
|
|
|
}
|
2007-05-04 15:14:56 +00:00
|
|
|
else {
|
|
|
|
/* Convert is bad, so do silence */
|
|
|
|
Uint32 num = wr*obtained.channels;
|
|
|
|
udata->num_in = rd;
|
|
|
|
udata->num_out = wr;
|
|
|
|
|
|
|
|
switch (pcm_channel_bytes)
|
|
|
|
{
|
|
|
|
case 1:
|
|
|
|
{
|
|
|
|
Uint8 *stream = udata->stream;
|
|
|
|
while (num-- > 0)
|
|
|
|
*stream++ = obtained.silence;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
Uint16 *stream = (Uint16 *)udata->stream;
|
|
|
|
while (num-- > 0)
|
|
|
|
*stream++ = obtained.silence;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2007-01-05 10:30:18 +00:00
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
if (udata->debug != NULL) {
|
|
|
|
fwrite(udata->stream, sizeof(Uint8), wr, udata->debug);
|
|
|
|
}
|
|
|
|
}
|
2007-01-05 10:30:18 +00:00
|
|
|
} else {
|
2007-05-04 15:14:56 +00:00
|
|
|
udata->num_in = udata->num_out = MIN(udata->num_in, udata->num_out);
|
2007-07-31 11:41:42 +00:00
|
|
|
SDL_MixAudio(udata->stream, pcm_data,
|
|
|
|
udata->num_out * pcm_sample_bytes, sim_volume);
|
2007-01-05 10:30:18 +00:00
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
if (udata->debug != NULL) {
|
|
|
|
fwrite(pcm_data, sizeof(Uint8), udata->num_out * pcm_sample_bytes,
|
|
|
|
udata->debug);
|
2007-01-05 10:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
void sdl_audio_callback(struct pcm_udata *udata, Uint8 *stream, int len)
|
2006-02-13 21:46:28 +00:00
|
|
|
{
|
2007-05-04 15:14:56 +00:00
|
|
|
udata->stream = stream;
|
2006-02-13 21:46:28 +00:00
|
|
|
|
2007-01-05 10:30:18 +00:00
|
|
|
/* Write what we have in the PCM buffer */
|
2007-05-04 15:14:56 +00:00
|
|
|
if (pcm_data_size > 0)
|
|
|
|
goto start;
|
2006-02-21 21:48:06 +00:00
|
|
|
|
2007-01-05 10:30:18 +00:00
|
|
|
/* Audio card wants more? Get some more then. */
|
|
|
|
while (len > 0) {
|
2007-05-04 15:14:56 +00:00
|
|
|
if ((ssize_t)pcm_data_size <= 0) {
|
2006-03-11 10:22:20 +00:00
|
|
|
pcm_data_size = 0;
|
2007-05-04 15:14:56 +00:00
|
|
|
|
|
|
|
if (callback_for_more)
|
|
|
|
callback_for_more(&pcm_data, &pcm_data_size);
|
2006-03-11 10:22:20 +00:00
|
|
|
}
|
2006-02-22 22:45:10 +00:00
|
|
|
|
2007-01-05 10:30:18 +00:00
|
|
|
if (pcm_data_size > 0) {
|
2007-05-04 15:14:56 +00:00
|
|
|
start:
|
|
|
|
udata->num_in = pcm_data_size / pcm_sample_bytes;
|
|
|
|
udata->num_out = len / pcm_sample_bytes;
|
|
|
|
|
|
|
|
write_to_soundcard(udata);
|
|
|
|
|
|
|
|
udata->num_in *= pcm_sample_bytes;
|
|
|
|
udata->num_out *= pcm_sample_bytes;
|
|
|
|
|
|
|
|
pcm_data += udata->num_in;
|
|
|
|
pcm_data_size -= udata->num_in;
|
|
|
|
udata->stream += udata->num_out;
|
|
|
|
len -= udata->num_out;
|
2006-03-11 10:22:20 +00:00
|
|
|
} else {
|
|
|
|
DEBUGF("sdl_audio_callback: No Data.\n");
|
2007-05-04 15:14:56 +00:00
|
|
|
sdl_dma_stop_nolock();
|
2006-03-11 10:22:20 +00:00
|
|
|
break;
|
2006-02-21 21:48:06 +00:00
|
|
|
}
|
2006-02-22 22:45:10 +00:00
|
|
|
}
|
2006-02-13 21:46:28 +00:00
|
|
|
}
|
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
#ifdef HAVE_RECORDING
|
|
|
|
void pcm_init_recording(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_close_recording(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_record_data(void (*more_ready)(void* start, size_t size),
|
|
|
|
void *start, size_t size)
|
|
|
|
{
|
|
|
|
(void)more_ready;
|
|
|
|
(void)start;
|
|
|
|
(void)size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_stop_recording(void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_record_more(void *start, size_t size)
|
|
|
|
{
|
|
|
|
(void)start;
|
|
|
|
(void)size;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pcm_calculate_rec_peaks(int *left, int *right)
|
|
|
|
{
|
|
|
|
if (left)
|
|
|
|
*left = 0;
|
|
|
|
if (right)
|
|
|
|
*right = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned long pcm_rec_status(void)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* HAVE_RECORDING */
|
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
int pcm_init(void)
|
|
|
|
{
|
2007-01-05 10:30:18 +00:00
|
|
|
SDL_AudioSpec wanted_spec;
|
2007-05-04 15:14:56 +00:00
|
|
|
udata.debug = NULL;
|
2006-02-21 21:48:06 +00:00
|
|
|
|
|
|
|
if (debug_audio) {
|
2007-05-04 15:14:56 +00:00
|
|
|
udata.debug = fopen("audiodebug.raw", "wb");
|
2006-02-21 21:48:06 +00:00
|
|
|
}
|
2006-02-13 21:46:28 +00:00
|
|
|
|
|
|
|
/* Set 16-bit stereo audio at 44Khz */
|
2007-01-05 10:30:18 +00:00
|
|
|
wanted_spec.freq = 44100;
|
|
|
|
wanted_spec.format = AUDIO_S16SYS;
|
|
|
|
wanted_spec.channels = 2;
|
|
|
|
wanted_spec.samples = 2048;
|
2007-05-04 15:14:56 +00:00
|
|
|
wanted_spec.callback =
|
|
|
|
(void (SDLCALL *)(void *userdata,
|
|
|
|
Uint8 *stream, int len))sdl_audio_callback;
|
|
|
|
wanted_spec.userdata = &udata;
|
2006-02-13 21:46:28 +00:00
|
|
|
|
|
|
|
/* Open the audio device and start playing sound! */
|
2007-01-05 10:30:18 +00:00
|
|
|
if(SDL_OpenAudio(&wanted_spec, &obtained) < 0) {
|
2006-02-13 21:46:28 +00:00
|
|
|
fprintf(stderr, "Unable to open audio: %s\n", SDL_GetError());
|
|
|
|
return -1;
|
|
|
|
}
|
2006-02-21 21:48:06 +00:00
|
|
|
|
2007-05-04 15:14:56 +00:00
|
|
|
switch (obtained.format)
|
|
|
|
{
|
|
|
|
case AUDIO_U8:
|
|
|
|
case AUDIO_S8:
|
|
|
|
pcm_channel_bytes = 1;
|
|
|
|
break;
|
|
|
|
case AUDIO_U16LSB:
|
|
|
|
case AUDIO_S16LSB:
|
|
|
|
case AUDIO_U16MSB:
|
|
|
|
case AUDIO_S16MSB:
|
|
|
|
pcm_channel_bytes = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
fprintf(stderr, "Unknown sample format obtained: %u\n",
|
|
|
|
(unsigned)obtained.format);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pcm_sample_bytes = obtained.channels * pcm_channel_bytes;
|
|
|
|
|
|
|
|
pcm_apply_settings_nolock();
|
|
|
|
|
|
|
|
sdl_dma_stop_nolock();
|
2006-02-03 15:19:58 +00:00
|
|
|
|
2006-02-13 21:46:28 +00:00
|
|
|
return 0;
|
2006-01-09 11:22:36 +00:00
|
|
|
}
|
|
|
|
|
2007-03-11 06:21:43 +00:00
|
|
|
void pcm_postinit(void)
|
|
|
|
{
|
|
|
|
}
|