- Fix for big apple architectures by Rogerio Brito, reworked by me to use bswap.h macros.

- Fix with audio only files.


git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@5838 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
atmos4 2002-04-26 13:07:03 +00:00
parent 020a695eb2
commit 1b990d79ec
1 changed files with 57 additions and 24 deletions

View File

@ -1,6 +1,9 @@
#include <stdio.h>
#include <stdlib.h>
#include "config.h"
#include "bswap.h"
#include "afmt.h"
#include "audio_out.h"
#include "audio_out_internal.h"
@ -42,21 +45,21 @@ struct WaveHeader
unsigned long data_length;
};
/* init with default values */
static struct WaveHeader wavhdr = {
WAV_ID_RIFF,
0x00000000,
WAV_ID_WAVE,
WAV_ID_FMT,
16,
WAV_ID_PCM,
2,
44100,
192000,
4,
16,
WAV_ID_DATA,
0x00000000
le2me_32(WAV_ID_RIFF),
le2me_32(0x00000000),
le2me_32(WAV_ID_WAVE),
le2me_32(WAV_ID_FMT),
le2me_32(16),
le2me_16(WAV_ID_PCM),
le2me_16(2),
le2me_32(44100),
le2me_32(192000),
le2me_16(4),
le2me_16(16),
le2me_32(WAV_ID_DATA),
le2me_32(0x00000000)
};
static FILE *fp = NULL;
@ -69,19 +72,34 @@ static int control(int cmd,int arg){
// open & setup audio device
// return: 1=success 0=fail
static int init(int rate,int channels,int format,int flags){
int bits;
if(!ao_outputfilename) {
ao_outputfilename = (char *) malloc(sizeof(char) * 14);
strcpy(ao_outputfilename,(ao_pcm_waveheader ? "audiodump.wav" : "audiodump.pcm"));
strcpy(ao_outputfilename,
(ao_pcm_waveheader ? "audiodump.wav" : "audiodump.pcm"));
}
wavhdr.channels = channels;
wavhdr.sample_rate = rate;
wavhdr.bytes_per_second = rate * (format / 8) * channels;
wavhdr.bits = format;
/* bits is only equal to format if (format == 8) or (format == 16);
this means that the following "if" is a kludge and should
really be a switch to be correct in all cases */
if (format == AFMT_S16_BE) { bits = 16; }
else { bits = format; }
wavhdr.channels = le2me_16(channels);
wavhdr.sample_rate = le2me_32(rate);
wavhdr.bytes_per_second = rate * (bits / 8) * channels;
wavhdr.bytes_per_second = le2me_32(wavhdr.bytes_per_second);
wavhdr.bits = le2me_16(bits);
printf("PCM: File: %s (%s)\n"
"PCM: Samplerate: %iHz Channels: %s Format %s\n",
ao_outputfilename, (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate,
(channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
printf("PCM: Info: fastest dumping is achieved with -vo null "
"-hardframedrop.\n"
"PCM: Info: to write WAVE files use -waveheader (default); "
"for RAW PCM -nowaveheader.\n");
printf("PCM: File: %s (%s) Samplerate: %iHz Channels: %s Format %s\n", ao_outputfilename, (ao_pcm_waveheader?"WAVE":"RAW PCM"), rate, (channels > 1) ? "Stereo" : "Mono", audio_out_format_name(format));
printf("PCM: Info - fastest dumping is achieved with -vo null -hardframedrop.\n");
printf("PCM: Info - to write WAVE files use -waveheader (default), for RAW PCM -nowaveheader.\n");
fp = fopen(ao_outputfilename, "wb");
ao_data.outburst = 65536;
@ -101,6 +119,7 @@ static void uninit(){
if(ao_pcm_waveheader){ /* Write wave header */
wavhdr.file_length = wavhdr.data_length + sizeof(wavhdr) - 8;
wavhdr.file_length = le2me_32(wavhdr.file_length);
fseek(fp, 0, SEEK_SET);
fwrite(&wavhdr,sizeof(wavhdr),1,fp);
}
@ -128,7 +147,9 @@ static void audio_resume()
// return: how many bytes can be played without blocking
static int get_space(){
return ao_data.pts < vo_pts ? ao_data.outburst : 0;
if(vo_pts)
return ao_data.pts < vo_pts ? ao_data.outburst : 0;
return ao_data.outburst;
}
// plays 'len' bytes of 'data'
@ -136,9 +157,21 @@ static int get_space(){
// return: number of bytes played
static int play(void* data,int len,int flags){
#ifdef WORDS_BIGENDIAN
register int i;
unsigned short *buffer = (unsigned short *) data;
if (wavhdr.bits == le2me_16(16)) {
for(i = 0; i < len/2; ++i) {
buffer[i] = le2me_16(buffer[i]);
}
}
/* FIXME: take care of cases with more than 8 bits here? */
#endif
//printf("PCM: Writing chunk!\n");
fwrite(data,len,1,fp);
if(ao_pcm_waveheader)
wavhdr.data_length += len;