aboutsummaryrefslogtreecommitdiffstats
path: root/src/audioOutputs/audioOutput_shout.c
diff options
context:
space:
mode:
authorWarren Dukes <warren.dukes@gmail.com>2004-11-02 17:05:27 +0000
committerWarren Dukes <warren.dukes@gmail.com>2004-11-02 17:05:27 +0000
commitee5d5d633016948f3ecf2d5f9875d7e8223f9a36 (patch)
treeeb58a5f4ed032e6f28ff0e7f5bdaae29dd937e38 /src/audioOutputs/audioOutput_shout.c
parent02982397700a02cb095970023ff9e8618638cc0c (diff)
downloadmpd-ee5d5d633016948f3ecf2d5f9875d7e8223f9a36.tar.gz
mpd-ee5d5d633016948f3ecf2d5f9875d7e8223f9a36.tar.xz
mpd-ee5d5d633016948f3ecf2d5f9875d7e8223f9a36.zip
abstract out audioFormat conversion from shout plugin to the audioOutput layer,
now format can be specified for each different audioOutput device git-svn-id: https://svn.musicpd.org/mpd/trunk@2474 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/audioOutputs/audioOutput_shout.c')
-rw-r--r--src/audioOutputs/audioOutput_shout.c72
1 files changed, 15 insertions, 57 deletions
diff --git a/src/audioOutputs/audioOutput_shout.c b/src/audioOutputs/audioOutput_shout.c
index acd9f96e8..12ef8c968 100644
--- a/src/audioOutputs/audioOutput_shout.c
+++ b/src/audioOutputs/audioOutput_shout.c
@@ -59,13 +59,6 @@ typedef struct _ShoutData {
float quality;
int bitrate;
- AudioFormat outAudioFormat;
- AudioFormat inAudioFormat;
-
- char * convBuffer;
- size_t convBufferLen;
- /* shoud we convert the audio to a different format? */
- int audioFormatConvert;
int opened;
@@ -74,14 +67,15 @@ typedef struct _ShoutData {
int connAttempts;
time_t lastAttempt;
+
+ /* just a pointer to audioOutput->outAudioFormat */
+ AudioFormat * audioFormat;
} ShoutData;
static ShoutData * newShoutData() {
ShoutData * ret = malloc(sizeof(ShoutData));
ret->shoutConn = shout_new();
- ret->convBuffer = NULL;
- ret->convBufferLen = 0;
ret->opened = 0;
ret->tag = NULL;
ret->tagToSend = 0;
@@ -89,6 +83,7 @@ static ShoutData * newShoutData() {
ret->quality = -1.0;
ret->connAttempts = 0;
ret->lastAttempt = 0;
+ ret->audioFormat = NULL;
return ret;
}
@@ -96,7 +91,6 @@ static ShoutData * newShoutData() {
static void freeShoutData(ShoutData * sd) {
if(sd->shoutConn) shout_free(sd->shoutConn);
if(sd->tag) freeMpdTag(sd->tag);
- if(sd->convBuffer) free(sd->convBuffer);
free(sd);
}
@@ -194,11 +188,7 @@ static int myShout_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
}
checkBlockParam("format");
-
- if(0 != parseAudioConfig(&(sd->outAudioFormat), blockParam->value)) {
- ERROR("error parsing format at line %i\n", blockParam->line);
- exit(EXIT_FAILURE);
- }
+ sd->audioFormat = &audioOutput->outAudioFormat;
if(shout_set_host(sd->shoutConn, host) != SHOUTERR_SUCCESS ||
shout_set_port(sd->shoutConn, port) != SHOUTERR_SUCCESS ||
@@ -222,11 +212,11 @@ static int myShout_initDriver(AudioOutput * audioOutput, ConfigParam * param) {
char temp[11];
memset(temp, 0, sizeof(temp));
- snprintf(temp, sizeof(temp), "%d", sd->outAudioFormat.channels);
+ snprintf(temp, sizeof(temp), "%d", sd->audioFormat->channels);
shout_set_audio_info(sd->shoutConn, SHOUT_AI_CHANNELS, temp);
- snprintf(temp, sizeof(temp), "%d",
- sd->outAudioFormat.sampleRate);
+ snprintf(temp, sizeof(temp), "%d", sd->audioFormat->sampleRate);
+
shout_set_audio_info(sd->shoutConn, SHOUT_AI_SAMPLERATE, temp);
if(sd->quality >= 0) {
@@ -352,8 +342,8 @@ static int initEncoder(ShoutData * sd) {
if(sd->quality >= 0) {
if( 0 != vorbis_encode_init_vbr(&(sd->vi),
- sd->outAudioFormat.channels,
- sd->outAudioFormat.sampleRate, sd->quality*0.1) )
+ sd->audioFormat->channels,
+ sd->audioFormat->sampleRate, sd->quality*0.1) )
{
ERROR("problem seting up vorbis encoder for shout\n");
vorbis_info_clear(&(sd->vi));
@@ -362,8 +352,8 @@ static int initEncoder(ShoutData * sd) {
}
else {
if( 0 != vorbis_encode_init(&(sd->vi),
- sd->outAudioFormat.channels,
- sd->outAudioFormat.sampleRate, -1.0,
+ sd->audioFormat->channels,
+ sd->audioFormat->sampleRate, -1.0,
sd->bitrate*1000, -1.0) )
{
ERROR("problem seting up vorbis encoder for shout\n");
@@ -439,15 +429,6 @@ static int myShout_openDevice(AudioOutput * audioOutput,
{
ShoutData * sd = (ShoutData *)audioOutput->data;
- memcpy(&(sd->inAudioFormat), audioFormat, sizeof(AudioFormat));
-
- if(0 == memcmp(&(sd->inAudioFormat), &(sd->outAudioFormat),
- sizeof(AudioFormat)))
- {
- sd->audioFormatConvert = 0;
- }
- else sd->audioFormatConvert = 1;
-
audioOutput->open = 1;
if(sd->opened) return 0;
@@ -460,25 +441,6 @@ static int myShout_openDevice(AudioOutput * audioOutput,
return 0;
}
-static void myShout_convertAudioFormat(ShoutData * sd, char ** chunkArgPtr,
- int * sizeArgPtr)
-{
- int size = pcm_sizeOfOutputBufferForAudioFormatConversion(
- &(sd->inAudioFormat), *sizeArgPtr,
- &(sd->outAudioFormat));
-
- if(size > sd->convBufferLen) {
- sd->convBuffer = realloc(sd->convBuffer, size);
- sd->convBufferLen = size;
- }
-
- pcm_convertAudioFormat(&(sd->inAudioFormat), *chunkArgPtr, *sizeArgPtr,
- &(sd->outAudioFormat), sd->convBuffer);
-
- *sizeArgPtr = size;
- *chunkArgPtr = sd->convBuffer;
-}
-
static void myShout_sendMetadata(ShoutData * sd) {
ogg_int64_t granulepos = sd->vd.granulepos;
@@ -516,7 +478,7 @@ static int myShout_play(AudioOutput * audioOutput, char * playChunk, int size) {
ShoutData * sd = (ShoutData *)audioOutput->data;
float ** vorbbuf;
int samples;
- int bytes = sd->outAudioFormat.bits/8;
+ int bytes = sd->audioFormat->bits/8;
if(sd->opened && sd->tagToSend) myShout_sendMetadata(sd);
@@ -526,18 +488,14 @@ static int myShout_play(AudioOutput * audioOutput, char * playChunk, int size) {
}
}
- if(sd->audioFormatConvert) {
- myShout_convertAudioFormat(sd, &playChunk, &size);
- }
-
- samples = size/(bytes*sd->outAudioFormat.channels);
+ samples = size/(bytes*sd->audioFormat->channels);
/* this is for only 16-bit audio */
vorbbuf = vorbis_analysis_buffer(&(sd->vd), samples);
for(i=0; i<samples; i++) {
- for(j=0; j<sd->outAudioFormat.channels; j++) {
+ for(j=0; j<sd->audioFormat->channels; j++) {
vorbbuf[j][i] = (*((mpd_sint16 *)playChunk)) / 32768.0;
playChunk += bytes;
}