[xiph-commits] r3337 -
libfishsound/branches/1.0-stable-flac/src/libfishsound
conrad at svn.annodex.net
conrad at svn.annodex.net
Fri Jan 11 05:47:07 PST 2008
Author: conrad
Date: 2008-01-11 05:47:07 -0800 (Fri, 11 Jan 2008)
New Revision: 3337
Modified:
libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c
Log:
implement fs_encode_f (non-interleaved encode)
Modified: libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c
===================================================================
--- libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c 2008-01-11 13:10:08 UTC (rev 3336)
+++ libfishsound/branches/1.0-stable-flac/src/libfishsound/flac.c 2008-01-11 13:47:07 UTC (rev 3337)
@@ -64,7 +64,7 @@
unsigned char major, minor;
} version;
unsigned short header_packets;
- void* pcm;
+ void * ipcm;
} FishSoundFlacInfo;
int
@@ -131,11 +131,17 @@
{
FishSound* fsound = (FishSound*)client_data;
FishSoundFlacInfo* fi = (FishSoundFlacInfo *)fsound->codec_data;
- int i, j, offset;
+ int i, j, channels, blocksize, offset;
+
+ channels = frame->header.channels;
+ blocksize = frame->header.blocksize;
+
#ifdef DEBUG
- printf("fs_flac_write_callback: IN\n");
+ printf("fs_flac_write_callback: IN, blocksize %d\n", blocksize);
#endif
- fsound->frameno += frame->header.blocksize*frame->header.channels;
+
+ fsound->frameno += blocksize * channels;
+
if (fsound->callback.decoded_float) {
float norm = 1.0 / ((1 << (frame->header.bits_per_sample - 1)));
@@ -143,28 +149,31 @@
FishSoundDecoded_FloatIlv dfi;
float* retpcm;
- fi->pcm = realloc(fi->pcm, sizeof(float)*frame->header.channels*frame->header.blocksize);
- retpcm = (float*) fi->pcm;
- for (i=0; i<frame->header.blocksize; i++) {
- offset = i*frame->header.channels;
- for (j=0; j<frame->header.channels; j++)
+ fi->ipcm = realloc(fi->ipcm, sizeof(float) * channels * blocksize);
+ retpcm = (float*) fi->ipcm;
+ for (i = 0; i < blocksize; i++) {
+ offset = i * channels;
+ for (j = 0; j < channels; j++)
retpcm[offset + j] = buffer[j][i] * norm;
}
dfi = (FishSoundDecoded_FloatIlv)fsound->callback.decoded_float_ilv;
- dfi (fsound, (float **)retpcm, frame->header.blocksize, fsound->user_data);
+ dfi (fsound, (float **)retpcm, blocksize, fsound->user_data);
} else {
FishSoundDecoded_Float df;
- float** retpcm, *p;
+ float ** retpcm, *p;
+ FLAC__int32 * s = (FLAC__int32 *)buffer;
- fi->pcm = realloc(fi->pcm, sizeof(float)*frame->header.channels*frame->header.blocksize);
- retpcm = fi->pcm;
- for (i=0; i<frame->header.blocksize; i++)
- for (j=0; j<frame->header.channels; j++) {
+ fi->ipcm = realloc(fi->ipcm, sizeof(float) * channels * blocksize);
+ retpcm = fi->ipcm;
+ for (i = 0; i < blocksize; i++)
+ for (j = 0; j < channels; j++) {
+#if 0
p = retpcm[j];
- p[i] = buffer[j][i] * norm;
+ p[i] = s[i*channels + j] * norm;
+#endif
}
df = (FishSoundDecoded_Float)fsound->callback.decoded_float;
- df (fsound, retpcm, frame->header.blocksize, fsound->user_data);
+ df (fsound, retpcm, blocksize, fsound->user_data);
}
}
return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
@@ -251,9 +260,11 @@
fs_flac_decode (FishSound * fsound, unsigned char * buf, long bytes)
{
FishSoundFlacInfo *fi = fsound->codec_data;
+
#ifdef DEBUG
- printf("fs_flac_decode: IN, fi->packetno = %d\n", fi->packetno);
+ printf("fs_flac_decode: IN, fi->packetno = %ld\n", fi->packetno);
#endif
+
if (fi->packetno == 0) {
if (fs_flac_decode_header (fsound, buf, bytes) == NULL) {
#ifdef DEBUG
@@ -391,6 +402,8 @@
#endif
break;
}
+
+ return;
}
static FishSound *
@@ -411,24 +424,61 @@
}
static long
+fs_flac_encode_f (FishSound * fsound, float * pcm[], long frames)
+{
+ FishSoundFlacInfo *fi = fsound->codec_data;
+ FLAC__int32 *buffer;
+ float * p, norm = (1 << (BITS_PER_SAMPLE - 1));
+ long i;
+ int j, channels = fsound->info.channels;
+
+#ifdef DEBUG
+ printf("fs_flac_encode_f: IN, frames = %ld\n", frames);
+#endif
+
+ fi->ipcm = realloc(fi->ipcm, sizeof(FLAC__int32) * channels * frames);
+ buffer = (FLAC__int32*) fi->ipcm;
+ for (i = 0; i < frames; i++) {
+ for (j = 0; j < channels; j++) {
+ p = pcm[j];
+ buffer[i*channels + j] = (FLAC__int32) (p[i] * norm);
+ }
+ }
+
+ if (fi->packetno == 0)
+ fs_flac_enc_headers (fsound);
+
+ /* We could have used FLAC__stream_encoder_process() and a more direct
+ * conversion loop above, rather than converting and interleaving. */
+ FLAC__stream_encoder_process_interleaved(fi->fse, buffer, frames);
+
+ fi->packetno++;
+
+ return frames;
+}
+
+static long
fs_flac_encode_f_ilv (FishSound * fsound, float ** pcm, long frames)
{
FishSoundFlacInfo *fi = fsound->codec_data;
FLAC__int32 *buffer;
float * p = (float*)pcm, norm = (1 << (BITS_PER_SAMPLE - 1));
- int i;
- long length = frames * fsound->info.channels;
+ long i, length = frames * fsound->info.channels;
+
#ifdef DEBUG
printf("fs_flac_encode_f_ilv: IN, frames = %ld\n", frames);
#endif
- fi->pcm = realloc(fi->pcm, sizeof(FLAC__int32)*fsound->info.channels*frames);
- buffer = (FLAC__int32*) fi->pcm;
+
+ fi->ipcm = realloc(fi->ipcm, sizeof(FLAC__int32)*fsound->info.channels*frames);
+ buffer = (FLAC__int32*) fi->ipcm;
for (i=0; i<length; i++)
buffer[i] = p[i] * norm;
if (fi->packetno == 0)
fs_flac_enc_headers (fsound);
+
FLAC__stream_encoder_process_interleaved(fi->fse, buffer, frames);
+
fi->packetno++;
return frames;
@@ -446,6 +496,10 @@
{
FishSoundFlacInfo * fi = (FishSoundFlacInfo *)fsound->codec_data;
+#ifdef DEBUG
+ printf("fs_flac_delete: IN\n");
+#endif
+
if (fsound->mode == FISH_SOUND_DECODE) {
FLAC__stream_decoder_finish(fi->fsd);
FLAC__stream_decoder_delete(fi->fsd);
@@ -454,7 +508,7 @@
FLAC__stream_encoder_delete(fi->fse);
if (fi->buffer) fs_free(fi->buffer);
}
- if (fi->pcm) fs_free(fi->pcm);
+ if (fi->ipcm) fs_free(fi->ipcm);
fs_free (fi);
fsound->codec_data = NULL;
@@ -508,7 +562,7 @@
if (fi == NULL) return NULL;
fi->packetno = 0;
fi->header = 0;
- fi->pcm = NULL;
+ fi->ipcm = NULL;
fi->header_packets = 0;
fi->fsd = NULL;
fi->fse = NULL;
@@ -535,7 +589,7 @@
codec->update = fs_flac_update;
codec->command = fs_flac_command;
codec->decode = fs_flac_decode;
- codec->encode_f = NULL;
+ codec->encode_f = fs_flac_encode_f;
codec->encode_f_ilv = fs_flac_encode_f_ilv;
codec->flush = fs_flac_flush;
More information about the commits
mailing list