diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/codecs/libcook/main.c | 80 | ||||
-rw-r--r-- | apps/codecs/libcook/rm2wav.c | 80 |
2 files changed, 80 insertions, 80 deletions
diff --git a/apps/codecs/libcook/main.c b/apps/codecs/libcook/main.c index 3c671e0c3f..c13e74a201 100644 --- a/apps/codecs/libcook/main.c +++ b/apps/codecs/libcook/main.c | |||
@@ -37,6 +37,86 @@ | |||
37 | # endif | 37 | # endif |
38 | #endif | 38 | #endif |
39 | 39 | ||
40 | static unsigned char wav_header[44]={ | ||
41 | 'R','I','F','F',// 0 - ChunkID | ||
42 | 0,0,0,0, // 4 - ChunkSize (filesize-8) | ||
43 | 'W','A','V','E',// 8 - Format | ||
44 | 'f','m','t',' ',// 12 - SubChunkID | ||
45 | 16,0,0,0, // 16 - SubChunk1ID // 16 for PCM | ||
46 | 1,0, // 20 - AudioFormat (1=Uncompressed) | ||
47 | 2,0, // 22 - NumChannels | ||
48 | 0,0,0,0, // 24 - SampleRate in Hz | ||
49 | 0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8) | ||
50 | 4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8) | ||
51 | 16,0, // 34 - BitsPerSample | ||
52 | 'd','a','t','a',// 36 - Subchunk2ID | ||
53 | 0,0,0,0 // 40 - Subchunk2Size | ||
54 | }; | ||
55 | |||
56 | int open_wav(char* filename) { | ||
57 | int fd,res; | ||
58 | |||
59 | fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR); | ||
60 | if (fd >= 0) { | ||
61 | res = write(fd,wav_header,sizeof(wav_header)); | ||
62 | } | ||
63 | |||
64 | return(fd); | ||
65 | } | ||
66 | |||
67 | void close_wav(int fd, RMContext *rmctx) { | ||
68 | int x,res; | ||
69 | int filesize; | ||
70 | int bytes_per_sample = 2; | ||
71 | int samples_per_frame = rmctx->samples_pf_pc; | ||
72 | int nb_channels = rmctx->nb_channels; | ||
73 | int sample_rate = rmctx->sample_rate; | ||
74 | int nb_frames = rmctx->audio_framesize/rmctx->block_align * rmctx->nb_packets - 2; // first 2 frames have no valid audio; skipped in output | ||
75 | |||
76 | filesize= samples_per_frame*bytes_per_sample*nb_frames +44; | ||
77 | printf("Filesize = %d\n",filesize); | ||
78 | |||
79 | // ChunkSize | ||
80 | x=filesize-8; | ||
81 | wav_header[4]=(x&0xff); | ||
82 | wav_header[5]=(x&0xff00)>>8; | ||
83 | wav_header[6]=(x&0xff0000)>>16; | ||
84 | wav_header[7]=(x&0xff000000)>>24; | ||
85 | |||
86 | // Number of channels | ||
87 | wav_header[22]=nb_channels; | ||
88 | |||
89 | // Samplerate | ||
90 | wav_header[24]=sample_rate&0xff; | ||
91 | wav_header[25]=(sample_rate&0xff00)>>8; | ||
92 | wav_header[26]=(sample_rate&0xff0000)>>16; | ||
93 | wav_header[27]=(sample_rate&0xff000000)>>24; | ||
94 | |||
95 | // ByteRate | ||
96 | x=sample_rate*bytes_per_sample*nb_channels; | ||
97 | wav_header[28]=(x&0xff); | ||
98 | wav_header[29]=(x&0xff00)>>8; | ||
99 | wav_header[30]=(x&0xff0000)>>16; | ||
100 | wav_header[31]=(x&0xff000000)>>24; | ||
101 | |||
102 | // BlockAlign | ||
103 | wav_header[32]=rmctx->block_align;//2*rmctx->nb_channels; | ||
104 | |||
105 | // Bits per sample | ||
106 | wav_header[34]=16; | ||
107 | |||
108 | // Subchunk2Size | ||
109 | x=filesize-44; | ||
110 | wav_header[40]=(x&0xff); | ||
111 | wav_header[41]=(x&0xff00)>>8; | ||
112 | wav_header[42]=(x&0xff0000)>>16; | ||
113 | wav_header[43]=(x&0xff000000)>>24; | ||
114 | |||
115 | lseek(fd,0,SEEK_SET); | ||
116 | res = write(fd,wav_header,sizeof(wav_header)); | ||
117 | close(fd); | ||
118 | } | ||
119 | |||
40 | int main(int argc, char *argv[]) | 120 | int main(int argc, char *argv[]) |
41 | { | 121 | { |
42 | int fd, fd_dec; | 122 | int fd, fd_dec; |
diff --git a/apps/codecs/libcook/rm2wav.c b/apps/codecs/libcook/rm2wav.c index 4ef1ec4f66..f2e9635bfc 100644 --- a/apps/codecs/libcook/rm2wav.c +++ b/apps/codecs/libcook/rm2wav.c | |||
@@ -44,86 +44,6 @@ | |||
44 | /* ASF codec IDs */ | 44 | /* ASF codec IDs */ |
45 | #define CODEC_ID_WMAV1 0x160 | 45 | #define CODEC_ID_WMAV1 0x160 |
46 | #define CODEC_ID_WMAV2 0x161 | 46 | #define CODEC_ID_WMAV2 0x161 |
47 | |||
48 | static unsigned char wav_header[44]={ | ||
49 | 'R','I','F','F',// 0 - ChunkID | ||
50 | 0,0,0,0, // 4 - ChunkSize (filesize-8) | ||
51 | 'W','A','V','E',// 8 - Format | ||
52 | 'f','m','t',' ',// 12 - SubChunkID | ||
53 | 16,0,0,0, // 16 - SubChunk1ID // 16 for PCM | ||
54 | 1,0, // 20 - AudioFormat (1=Uncompressed) | ||
55 | 2,0, // 22 - NumChannels | ||
56 | 0,0,0,0, // 24 - SampleRate in Hz | ||
57 | 0,0,0,0, // 28 - Byte Rate (SampleRate*NumChannels*(BitsPerSample/8) | ||
58 | 4,0, // 32 - BlockAlign (== NumChannels * BitsPerSample/8) | ||
59 | 16,0, // 34 - BitsPerSample | ||
60 | 'd','a','t','a',// 36 - Subchunk2ID | ||
61 | 0,0,0,0 // 40 - Subchunk2Size | ||
62 | }; | ||
63 | |||
64 | int open_wav(char* filename) { | ||
65 | int fd,res; | ||
66 | |||
67 | fd=open(filename,O_CREAT|O_WRONLY|O_TRUNC,S_IRUSR|S_IWUSR); | ||
68 | if (fd >= 0) { | ||
69 | res = write(fd,wav_header,sizeof(wav_header)); | ||
70 | } | ||
71 | |||
72 | return(fd); | ||
73 | } | ||
74 | |||
75 | void close_wav(int fd, RMContext *rmctx) { | ||
76 | int x,res; | ||
77 | int filesize; | ||
78 | int bytes_per_sample = 2; | ||
79 | int samples_per_frame = rmctx->samples_pf_pc; | ||
80 | int nb_channels = rmctx->nb_channels; | ||
81 | int sample_rate = rmctx->sample_rate; | ||
82 | int nb_frames = rmctx->audio_framesize/rmctx->block_align * rmctx->nb_packets - 2; // first 2 frames have no valid audio; skipped in output | ||
83 | |||
84 | filesize= samples_per_frame*bytes_per_sample*nb_frames +44; | ||
85 | printf("Filesize = %d\n",filesize); | ||
86 | |||
87 | // ChunkSize | ||
88 | x=filesize-8; | ||
89 | wav_header[4]=(x&0xff); | ||
90 | wav_header[5]=(x&0xff00)>>8; | ||
91 | wav_header[6]=(x&0xff0000)>>16; | ||
92 | wav_header[7]=(x&0xff000000)>>24; | ||
93 | |||
94 | // Number of channels | ||
95 | wav_header[22]=nb_channels; | ||
96 | |||
97 | // Samplerate | ||
98 | wav_header[24]=sample_rate&0xff; | ||
99 | wav_header[25]=(sample_rate&0xff00)>>8; | ||
100 | wav_header[26]=(sample_rate&0xff0000)>>16; | ||
101 | wav_header[27]=(sample_rate&0xff000000)>>24; | ||
102 | |||
103 | // ByteRate | ||
104 | x=sample_rate*bytes_per_sample*nb_channels; | ||
105 | wav_header[28]=(x&0xff); | ||
106 | wav_header[29]=(x&0xff00)>>8; | ||
107 | wav_header[30]=(x&0xff0000)>>16; | ||
108 | wav_header[31]=(x&0xff000000)>>24; | ||
109 | |||
110 | // BlockAlign | ||
111 | wav_header[32]=rmctx->block_align;//2*rmctx->nb_channels; | ||
112 | |||
113 | // Bits per sample | ||
114 | wav_header[34]=16; | ||
115 | |||
116 | // Subchunk2Size | ||
117 | x=filesize-44; | ||
118 | wav_header[40]=(x&0xff); | ||
119 | wav_header[41]=(x&0xff00)>>8; | ||
120 | wav_header[42]=(x&0xff0000)>>16; | ||
121 | wav_header[43]=(x&0xff000000)>>24; | ||
122 | |||
123 | lseek(fd,0,SEEK_SET); | ||
124 | res = write(fd,wav_header,sizeof(wav_header)); | ||
125 | close(fd); | ||
126 | } | ||
127 | 47 | ||
128 | /* Some Rockbox-like functions (these should be implemented in metadata_common.[ch] */ | 48 | /* Some Rockbox-like functions (these should be implemented in metadata_common.[ch] */ |
129 | struct cook_extradata { | 49 | struct cook_extradata { |