generalize bits per sample (we support 8, 16, 32 - which is actually 24 with padding). also fix "the bug" which was using stream->channels instead of channels for open_params.Pipe.wInterleave. it would have been nice for OpenAudio to give us some reasonable error ;-)
git-svn-id: file:///srv/svn/repos/haiku/trunk/current@6508 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
2eabcdebe7
commit
0498000255
@ -124,7 +124,7 @@ extern char * pStatusStrs[ECHOSTATUS_LAST];
|
||||
|
||||
status_t
|
||||
echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
|
||||
uint8 b16, uint32 sample_rate)
|
||||
uint8 bitsPerSample, uint32 sample_rate)
|
||||
{
|
||||
int32 i;
|
||||
uint8 sample_size, frame_size;
|
||||
@ -146,7 +146,8 @@ echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
|
||||
open_params.bIsCyclic = TRUE;
|
||||
open_params.Pipe.nPipe = 0;
|
||||
open_params.Pipe.bIsInput = stream->use == ECHO_USE_RECORD ? TRUE : FALSE;
|
||||
open_params.Pipe.wInterleave = stream->channels;
|
||||
open_params.Pipe.wInterleave = channels;
|
||||
open_params.ProcessId = NULL;
|
||||
|
||||
status = stream->card->pEG->OpenAudio(&open_params, &stream->pipe);
|
||||
if(status!=ECHOSTATUS_OK) {
|
||||
@ -155,6 +156,7 @@ echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
PRINT(("VerifyAudioOpen\n"));
|
||||
status = stream->card->pEG->VerifyAudioOpen(stream->pipe);
|
||||
if(status!=ECHOSTATUS_OK) {
|
||||
PRINT(("echo_stream_set_audioparms : VerifyAudioOpen failed\n"));
|
||||
@ -163,11 +165,11 @@ echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
|
||||
}
|
||||
|
||||
if ((stream->channels == channels) &&
|
||||
(stream->b16 == b16) &&
|
||||
(stream->bitsPerSample == bitsPerSample) &&
|
||||
(stream->sample_rate == sample_rate))
|
||||
return B_OK;
|
||||
|
||||
format_params.wBitsPerSample = b16 == 0 ? 8 : 16;
|
||||
format_params.wBitsPerSample = bitsPerSample;
|
||||
format_params.byDataAreBigEndian = 0;
|
||||
format_params.byMonoToStereo = 0;
|
||||
format_params.wDataInterleave = channels == 1 ? 1 : 2;
|
||||
@ -179,6 +181,13 @@ echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status = stream->card->pEG->SetAudioFormat(stream->pipe, &format_params);
|
||||
if(status!=ECHOSTATUS_OK) {
|
||||
PRINT(("echo_stream_set_audioparms : bad format when setting\n"));
|
||||
PRINT((" status: %s \n", pStatusStrs[status]));
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
/* XXXX : setting sample rate is global in this driver */
|
||||
status = stream->card->pEG->QueryAudioSampleRate(sample_rate);
|
||||
if(status!=ECHOSTATUS_OK) {
|
||||
@ -187,13 +196,6 @@ echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
status = stream->card->pEG->SetAudioFormat(stream->pipe, &format_params);
|
||||
if(status!=ECHOSTATUS_OK) {
|
||||
PRINT(("echo_stream_set_audioparms : bad format when setting\n"));
|
||||
PRINT((" status: %s \n", pStatusStrs[status]));
|
||||
return B_ERROR;
|
||||
}
|
||||
|
||||
/* XXXX : setting sample rate is global in this driver */
|
||||
status = stream->card->pEG->SetAudioSampleRate(sample_rate);
|
||||
if(status!=ECHOSTATUS_OK) {
|
||||
@ -205,11 +207,11 @@ echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
|
||||
if(stream->buffer)
|
||||
echo_mem_free(stream->card, stream->buffer->log_base);
|
||||
|
||||
stream->b16 = b16;
|
||||
stream->bitsPerSample = bitsPerSample;
|
||||
stream->sample_rate = sample_rate;
|
||||
stream->channels = channels;
|
||||
|
||||
sample_size = stream->b16 + 1;
|
||||
sample_size = stream->bitsPerSample / 8;
|
||||
frame_size = sample_size * stream->channels;
|
||||
|
||||
stream->buffer = echo_mem_alloc(stream->card, stream->bufframes * frame_size * stream->bufcount);
|
||||
@ -249,7 +251,7 @@ echo_stream_get_nth_buffer(echo_stream *stream, uint8 chan, uint8 buf,
|
||||
uint8 sample_size, frame_size;
|
||||
LOG(("echo_stream_get_nth_buffer\n"));
|
||||
|
||||
sample_size = stream->b16 + 1;
|
||||
sample_size = stream->bitsPerSample / 8;
|
||||
frame_size = sample_size * stream->channels;
|
||||
|
||||
*buffer = (char*)stream->buffer->log_base + (buf * stream->bufframes * frame_size)
|
||||
@ -309,7 +311,7 @@ echo_stream_new(echo_dev *card, uint8 use, uint32 bufframes, uint8 bufcount)
|
||||
stream->card = card;
|
||||
stream->use = use;
|
||||
stream->state = !ECHO_STATE_STARTED;
|
||||
stream->b16 = 0;
|
||||
stream->bitsPerSample = 0;
|
||||
stream->sample_rate = 0;
|
||||
stream->channels = 0;
|
||||
stream->bufframes = bufframes;
|
||||
|
@ -56,7 +56,7 @@ typedef struct _echo_stream {
|
||||
struct _echo_dev *card;
|
||||
uint8 use;
|
||||
uint8 state;
|
||||
uint8 b16;
|
||||
uint8 bitsPerSample;
|
||||
uint32 sample_rate;
|
||||
uint8 channels;
|
||||
uint32 bufframes;
|
||||
@ -121,7 +121,7 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
status_t echo_stream_set_audioparms(echo_stream *stream, uint8 channels,
|
||||
uint8 b16, uint32 sample_rate);
|
||||
uint8 bitsPerSample, uint32 sample_rate);
|
||||
status_t echo_stream_get_nth_buffer(echo_stream *stream, uint8 chan, uint8 buf,
|
||||
char** buffer, size_t *stride);
|
||||
void echo_stream_start(echo_stream *stream, void (*inth) (void *), void *inthparam);
|
||||
|
@ -601,8 +601,8 @@ echo_open(const char *name, uint32 flags, void** cookie)
|
||||
|
||||
LOG(("stream_setaudio\n"));
|
||||
|
||||
echo_stream_set_audioparms(card->pstream, 2, true, 48000);
|
||||
echo_stream_set_audioparms(card->rstream, 2, true, 48000);
|
||||
echo_stream_set_audioparms(card->pstream, 2, 16, 48000);
|
||||
echo_stream_set_audioparms(card->rstream, 2, 16, 48000);
|
||||
|
||||
card->pstream->first_channel = 0;
|
||||
card->rstream->first_channel = 2;
|
||||
|
Loading…
Reference in New Issue
Block a user