diff options
author | Dave Chapman <dave@dchapman.com> | 2005-02-19 12:11:18 +0000 |
---|---|---|
committer | Dave Chapman <dave@dchapman.com> | 2005-02-19 12:11:18 +0000 |
commit | 4d961f21285de89360173ccc76ee82eb504d726e (patch) | |
tree | e41a8acd5f2879abd572de666bec36b8266e6a47 /apps/plugins/vorbis2wav.c | |
parent | 1839a956ba67fc601706bfd9d5f46a22c60bfc70 (diff) | |
download | rockbox-4d961f21285de89360173ccc76ee82eb504d726e.tar.gz rockbox-4d961f21285de89360173ccc76ee82eb504d726e.zip |
First version of vorbis decoder
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6017 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins/vorbis2wav.c')
-rw-r--r-- | apps/plugins/vorbis2wav.c | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/apps/plugins/vorbis2wav.c b/apps/plugins/vorbis2wav.c new file mode 100644 index 0000000000..3b5de72c74 --- /dev/null +++ b/apps/plugins/vorbis2wav.c | |||
@@ -0,0 +1,159 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 Björn Stenberg | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | |||
20 | #include "plugin.h" | ||
21 | |||
22 | #if (CONFIG_HWCODEC == MASNONE) | ||
23 | /* software codec platforms */ | ||
24 | |||
25 | #include <codecs/Tremor/ivorbisfile.h> | ||
26 | |||
27 | #include "lib/xxx2wav.h" /* Helper functions common to test decoders */ | ||
28 | |||
29 | static struct plugin_api* rb; | ||
30 | |||
31 | /* Some standard functions and variables needed by Tremor */ | ||
32 | |||
33 | int errno; | ||
34 | |||
35 | size_t strlen(const char *s) { | ||
36 | return(rb->strlen(s)); | ||
37 | } | ||
38 | |||
39 | char *strcpy(char *dest, const char *src) { | ||
40 | return(rb->strcpy(dest,src)); | ||
41 | } | ||
42 | |||
43 | char *strcat(char *dest, const char *src) { | ||
44 | return(rb->strcat(dest,src)); | ||
45 | } | ||
46 | |||
47 | size_t read_handler(void *ptr, size_t size, size_t nmemb, void *datasource) { | ||
48 | size_t len; | ||
49 | file_info_struct *p = (file_info_struct *) datasource; | ||
50 | |||
51 | if (p->curpos >= p->filesize) { | ||
52 | return 0; /* EOF */ | ||
53 | } | ||
54 | |||
55 | len=nmemb*size; | ||
56 | if ((long)(p->curpos+len) > (long)p->filesize) { len=p->filesize-p->curpos; } | ||
57 | |||
58 | rb->memcpy(ptr,&filebuf[p->curpos],len); | ||
59 | p->curpos+=len; | ||
60 | |||
61 | return(len); | ||
62 | } | ||
63 | |||
64 | int seek_handler(void *datasource, ogg_int64_t offset, int whence) { | ||
65 | /* We are not seekable at the moment */ | ||
66 | (void)datasource; | ||
67 | (void)offset; | ||
68 | (void)whence; | ||
69 | return -1; | ||
70 | } | ||
71 | |||
72 | int close_handler(void *datasource) { | ||
73 | (void)datasource; | ||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | long tell_handler(void *datasource) { | ||
78 | file_info_struct *p = (file_info_struct *) datasource; | ||
79 | return p->curpos; | ||
80 | } | ||
81 | |||
82 | |||
83 | /* this is the plugin entry point */ | ||
84 | enum plugin_status plugin_start(struct plugin_api* api, void* file) | ||
85 | { | ||
86 | ov_callbacks callbacks; | ||
87 | OggVorbis_File vf; | ||
88 | vorbis_info* vi; | ||
89 | |||
90 | int error; | ||
91 | long n; | ||
92 | int current_section; | ||
93 | int eof; | ||
94 | static char pcmbuf[4096]; | ||
95 | |||
96 | file_info_struct file_info; | ||
97 | |||
98 | TEST_PLUGIN_API(api); | ||
99 | |||
100 | /* if you are using a global api pointer, don't forget to copy it! | ||
101 | otherwise you will get lovely "I04: IllInstr" errors... :-) */ | ||
102 | rb = api; | ||
103 | |||
104 | |||
105 | /* This function sets up the buffers and reads the file into RAM */ | ||
106 | |||
107 | if (local_init(file,"/vorbistest.wav",&file_info,api)) { | ||
108 | return PLUGIN_ERROR; | ||
109 | } | ||
110 | |||
111 | /* Create a decoder instance */ | ||
112 | |||
113 | callbacks.read_func=read_handler; | ||
114 | callbacks.seek_func=seek_handler; | ||
115 | callbacks.tell_func=tell_handler; | ||
116 | callbacks.close_func=close_handler; | ||
117 | |||
118 | file_info.frames_decoded=0; | ||
119 | file_info.start_tick=*(rb->current_tick); | ||
120 | rb->button_clear_queue(); | ||
121 | |||
122 | error=ov_open_callbacks(&file_info,&vf,NULL,0,callbacks); | ||
123 | |||
124 | vi=ov_info(&vf,-1); | ||
125 | |||
126 | if (vi==NULL) { | ||
127 | rb->splash(HZ*2, true, "Error"); | ||
128 | } | ||
129 | file_info.samplerate=vi->rate; | ||
130 | |||
131 | eof=0; | ||
132 | while (!eof) { | ||
133 | /* Read host-endian signed 16 bit PCM samples */ | ||
134 | n=ov_read(&vf,pcmbuf,sizeof(pcmbuf),¤t_section); | ||
135 | |||
136 | if (n==0) { | ||
137 | eof=1; | ||
138 | } else if (n < 0) { | ||
139 | dprintf("Error decoding frame\n"); | ||
140 | } else { | ||
141 | file_info.frames_decoded++; | ||
142 | rb->write(file_info.outfile,pcmbuf,n); | ||
143 | file_info.current_sample+=(n/4); | ||
144 | } | ||
145 | |||
146 | display_status(&file_info); | ||
147 | |||
148 | if (rb->button_get(false)!=BUTTON_NONE) { | ||
149 | close_wav(&file_info); | ||
150 | return PLUGIN_OK; | ||
151 | } | ||
152 | } | ||
153 | |||
154 | close_wav(&file_info); | ||
155 | rb->splash(HZ*2, true, "FINISHED!"); | ||
156 | |||
157 | return PLUGIN_OK; | ||
158 | } | ||
159 | #endif /* CONFIG_HWCODEC == MASNONE */ | ||