misc/openalbridge/loaders.c
changeset 3362 8d3b4d19ce27
parent 3360 717b4e46e855
child 3364 e5403e2bf02c
equal deleted inserted replaced
3361:cfc6cd502f85 3362:8d3b4d19ce27
     1 /*
     1 /*
     2  * OpenAL Bridge - a simple portable library for OpenAL interface
     2 * OpenAL Bridge - a simple portable library for OpenAL interface
     3  * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
     3 * Copyright (c) 2009 Vittorio Giovara <vittorio.giovara@gmail.com>
     4  *
     4 *
     5  * This program is free software; you can redistribute it and/or modify
     5 * This program is free software; you can redistribute it and/or modify
     6  * it under the terms of the GNU Lesser General Public License as published by
     6 * it under the terms of the GNU Lesser General Public License as published by
     7  * the Free Software Foundation; version 2 of the License
     7 * the Free Software Foundation; version 2 of the License
     8  *
     8 *
     9  * This program is distributed in the hope that it will be useful,
     9 * This program is distributed in the hope that it will be useful,
    10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
    10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12  * GNU Lesser General Public License for more details.
    12 * GNU Lesser General Public License for more details.
    13  *
    13 *
    14  * You should have received a copy of the GNU Lesser General Public License
    14 * You should have received a copy of the GNU Lesser General Public License
    15  * along with this program; if not, write to the Free Software
    15 * along with this program; if not, write to the Free Software
    16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
    17  */
    17 */
    18 
    18 
    19 #include "loaders.h"
    19 #include "loaders.h"
    20 #include "wrappers.h"
    20 #include "wrappers.h"
    21 #include "vorbis/vorbisfile.h"
    21 #include "vorbis/vorbisfile.h"
    22 
    22 #include "openalbridge_t.h"
    23 #ifdef __CPLUSPLUS
    23 
    24 extern "C" {
    24 int load_wavpcm (const char *filename, ALenum *format, char ** data, ALsizei *bitsize, ALsizei *freq) {
    25 #endif 
    25     WAV_header_t WAVHeader;
    26     
    26     FILE *wavfile;
    27     int load_wavpcm (const char *filename, ALenum *format, char ** data, ALsizei *bitsize, ALsizei *freq) {
    27     int32_t t;
    28         WAV_header_t WAVHeader;
    28     uint32_t n = 0;
    29         FILE *wavfile;
    29     uint8_t sub0, sub1, sub2, sub3;
    30         int32_t t;
    30 
    31         uint32_t n = 0;
    31     wavfile = Fopen(filename, "rb");
    32         uint8_t sub0, sub1, sub2, sub3;
    32 
    33         
    33     fread(&WAVHeader.ChunkID, sizeof(uint32_t), 1, wavfile);                /*RIFF*/
    34         wavfile = Fopen(filename, "rb");
    34     fread(&WAVHeader.ChunkSize, sizeof(uint32_t), 1, wavfile);
    35         
    35     fread(&WAVHeader.Format, sizeof(uint32_t), 1, wavfile);                 /*WAVE*/
    36         fread(&WAVHeader.ChunkID, sizeof(uint32_t), 1, wavfile);                /*RIFF*/
    36 
    37         fread(&WAVHeader.ChunkSize, sizeof(uint32_t), 1, wavfile);
    37 #ifdef DEBUG
    38         fread(&WAVHeader.Format, sizeof(uint32_t), 1, wavfile);                 /*WAVE*/
    38     fprintf(stderr, "ChunkID: %X\n", ENDIAN_BIG_32(WAVHeader.ChunkID));
    39         
    39     fprintf(stderr, "ChunkSize: %d\n", ENDIAN_LITTLE_32(WAVHeader.ChunkSize));
    40 #ifdef DEBUG
    40     fprintf(stderr, "Format: %X\n", ENDIAN_BIG_32(WAVHeader.Format));
    41         fprintf(stderr, "ChunkID: %X\n", ENDIAN_BIG_32(WAVHeader.ChunkID));
    41 #endif
    42         fprintf(stderr, "ChunkSize: %d\n", ENDIAN_LITTLE_32(WAVHeader.ChunkSize));
    42 
    43         fprintf(stderr, "Format: %X\n", ENDIAN_BIG_32(WAVHeader.Format));
    43     fread(&WAVHeader.Subchunk1ID, sizeof(uint32_t), 1, wavfile);            /*fmt */
    44 #endif
    44     fread(&WAVHeader.Subchunk1Size, sizeof(uint32_t), 1, wavfile);
    45         
    45     fread(&WAVHeader.AudioFormat, sizeof(uint16_t), 1, wavfile);
    46         fread(&WAVHeader.Subchunk1ID, sizeof(uint32_t), 1, wavfile);            /*fmt */
    46     fread(&WAVHeader.NumChannels, sizeof(uint16_t), 1, wavfile);
    47         fread(&WAVHeader.Subchunk1Size, sizeof(uint32_t), 1, wavfile);
    47     fread(&WAVHeader.SampleRate, sizeof(uint32_t), 1, wavfile);
    48         fread(&WAVHeader.AudioFormat, sizeof(uint16_t), 1, wavfile);
    48     fread(&WAVHeader.ByteRate, sizeof(uint32_t), 1, wavfile);
    49         fread(&WAVHeader.NumChannels, sizeof(uint16_t), 1, wavfile);
    49     fread(&WAVHeader.BlockAlign, sizeof(uint16_t), 1, wavfile);
    50         fread(&WAVHeader.SampleRate, sizeof(uint32_t), 1, wavfile);
    50     fread(&WAVHeader.BitsPerSample, sizeof(uint16_t), 1, wavfile);
    51         fread(&WAVHeader.ByteRate, sizeof(uint32_t), 1, wavfile);
    51 
    52         fread(&WAVHeader.BlockAlign, sizeof(uint16_t), 1, wavfile);
    52 #ifdef DEBUG
    53         fread(&WAVHeader.BitsPerSample, sizeof(uint16_t), 1, wavfile);
    53     fprintf(stderr, "Subchunk1ID: %X\n", ENDIAN_BIG_32(WAVHeader.Subchunk1ID));
    54         
    54     fprintf(stderr, "Subchunk1Size: %d\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk1Size));
    55 #ifdef DEBUG
    55     fprintf(stderr, "AudioFormat: %d\n", ENDIAN_LITTLE_16(WAVHeader.AudioFormat));
    56         fprintf(stderr, "Subchunk1ID: %X\n", ENDIAN_BIG_32(WAVHeader.Subchunk1ID));
    56     fprintf(stderr, "NumChannels: %d\n", ENDIAN_LITTLE_16(WAVHeader.NumChannels));
    57         fprintf(stderr, "Subchunk1Size: %d\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk1Size));
    57     fprintf(stderr, "SampleRate: %d\n", ENDIAN_LITTLE_32(WAVHeader.SampleRate));
    58         fprintf(stderr, "AudioFormat: %d\n", ENDIAN_LITTLE_16(WAVHeader.AudioFormat));
    58     fprintf(stderr, "ByteRate: %d\n", ENDIAN_LITTLE_32(WAVHeader.ByteRate));
    59         fprintf(stderr, "NumChannels: %d\n", ENDIAN_LITTLE_16(WAVHeader.NumChannels));
    59     fprintf(stderr, "BlockAlign: %d\n", ENDIAN_LITTLE_16(WAVHeader.BlockAlign));
    60         fprintf(stderr, "SampleRate: %d\n", ENDIAN_LITTLE_32(WAVHeader.SampleRate));
    60     fprintf(stderr, "BitsPerSample: %d\n", ENDIAN_LITTLE_16(WAVHeader.BitsPerSample));
    61         fprintf(stderr, "ByteRate: %d\n", ENDIAN_LITTLE_32(WAVHeader.ByteRate));
    61 #endif
    62         fprintf(stderr, "BlockAlign: %d\n", ENDIAN_LITTLE_16(WAVHeader.BlockAlign));
    62 
    63         fprintf(stderr, "BitsPerSample: %d\n", ENDIAN_LITTLE_16(WAVHeader.BitsPerSample));
    63     /*remove useless header chunks by looking for the WAV_HEADER_SUBCHUNK2ID integer */
    64 #endif
    64     do {
    65         
    65         t = fread(&sub0, sizeof(uint8_t), 1, wavfile);
    66         /*remove useless header chunks by looking for the WAV_HEADER_SUBCHUNK2ID integer */
    66         if(sub0 == 0x64) {
    67         do {
    67             t = fread(&sub1, sizeof(uint8_t), 1, wavfile);
    68             t = fread(&sub0, sizeof(uint8_t), 1, wavfile);
    68             if(sub1 == 0x61) {
    69             if(sub0 == 0x64) {
    69                 t = fread(&sub2, sizeof(uint8_t), 1, wavfile);
    70                 t = fread(&sub1, sizeof(uint8_t), 1, wavfile);
    70                 if(sub2 == 0x74) {
    71                 if(sub1 == 0x61) {
    71                     t = fread(&sub3, sizeof(uint8_t), 1, wavfile);
    72                     t = fread(&sub2, sizeof(uint8_t), 1, wavfile);
    72                     if(sub3 == 0x61) {
    73                     if(sub2 == 0x74) {
    73                         WAVHeader.Subchunk2ID = WAV_HEADER_SUBCHUNK2ID;
    74                         t = fread(&sub3, sizeof(uint8_t), 1, wavfile);
    74                         break;
    75                         if(sub3 == 0x61) {
    75                     }
    76                             WAVHeader.Subchunk2ID = WAV_HEADER_SUBCHUNK2ID;
       
    77                             break;                                                
       
    78                         } 
       
    79                     }       
       
    80                 }
    76                 }
    81             }
    77             }
    82             
    78         }
    83             if (t <= 0) { 
    79 
    84                 /*eof*/
    80         if (t <= 0) {
       
    81             /*eof*/
       
    82             errno = EILSEQ;
       
    83             err_ret("(%s) ERROR - wrong WAV header", prog);
       
    84             return AL_FALSE;
       
    85         }
       
    86     } while (1);
       
    87 
       
    88     fread(&WAVHeader.Subchunk2Size, sizeof(uint32_t), 1, wavfile);
       
    89 
       
    90 #ifdef DEBUG
       
    91     fprintf(stderr, "Subchunk2ID: %X\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk2ID));
       
    92     fprintf(stderr, "Subchunk2Size: %d\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size));
       
    93 #endif
       
    94 
       
    95     *data = (char*) Malloc (sizeof(char) * ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size));
       
    96 
       
    97     /*read the actual sound data*/
       
    98     do {
       
    99         n += fread(&((*data)[n]), sizeof(uint8_t), 4, wavfile);
       
   100     } while (n < ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size));
       
   101 
       
   102     fclose(wavfile);
       
   103 
       
   104 #ifdef DEBUG
       
   105     err_msg("(%s) INFO - WAV data loaded", prog);
       
   106 #endif
       
   107 
       
   108     /*set parameters for OpenAL*/
       
   109     /*Valid formats are AL_FORMAT_MONO8, AL_FORMAT_MONO16, AL_FORMAT_STEREO8, and AL_FORMAT_STEREO16*/
       
   110     if (ENDIAN_LITTLE_16(WAVHeader.NumChannels) == 1) {
       
   111         if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 8)
       
   112             *format = AL_FORMAT_MONO8;
       
   113         else {
       
   114             if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 16)
       
   115                 *format = AL_FORMAT_MONO16;
       
   116             else {
    85                 errno = EILSEQ;
   117                 errno = EILSEQ;
    86                 err_ret("(%s) ERROR - wrong WAV header", prog);
   118                 err_ret("(%s) ERROR - wrong WAV header [bitsample value]", prog);
    87                 return AL_FALSE;
   119                 return AL_FALSE;
    88             }
   120             }
    89         } while (1);
   121         }
    90         
   122     } else {
    91         fread(&WAVHeader.Subchunk2Size, sizeof(uint32_t), 1, wavfile);
   123         if (ENDIAN_LITTLE_16(WAVHeader.NumChannels) == 2) {
    92         
       
    93 #ifdef DEBUG
       
    94         fprintf(stderr, "Subchunk2ID: %X\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk2ID));
       
    95         fprintf(stderr, "Subchunk2Size: %d\n", ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size));
       
    96 #endif
       
    97         
       
    98         *data = (char*) Malloc (sizeof(char) * ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size));
       
    99         
       
   100         /*read the actual sound data*/
       
   101         do {
       
   102             n += fread(&((*data)[n]), sizeof(uint8_t), 4, wavfile);
       
   103         } while (n < ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size));
       
   104         
       
   105         fclose(wavfile);	
       
   106         
       
   107 #ifdef DEBUG
       
   108         err_msg("(%s) INFO - WAV data loaded", prog);
       
   109 #endif
       
   110         
       
   111         /*set parameters for OpenAL*/
       
   112         /*Valid formats are AL_FORMAT_MONO8, AL_FORMAT_MONO16, AL_FORMAT_STEREO8, and AL_FORMAT_STEREO16*/
       
   113         if (ENDIAN_LITTLE_16(WAVHeader.NumChannels) == 1) {
       
   114             if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 8)
   124             if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 8)
   115                 *format = AL_FORMAT_MONO8;
   125                 *format = AL_FORMAT_STEREO8;
   116             else {
   126             else {
   117                 if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 16)
   127                 if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 16)
   118                     *format = AL_FORMAT_MONO16;
   128                     *format = AL_FORMAT_STEREO16;
   119                 else {
   129                 else {
   120                     errno = EILSEQ;
   130                     errno = EILSEQ;
   121                     err_ret("(%s) ERROR - wrong WAV header [bitsample value]", prog);
   131                     err_ret("(%s) ERROR - wrong WAV header [bitsample value]", prog);
   122                     return AL_FALSE;
   132                     return AL_FALSE;
   123                 }
   133                 }
   124             } 
   134             }
   125         } else {
   135         } else {
   126             if (ENDIAN_LITTLE_16(WAVHeader.NumChannels) == 2) {
   136             errno = EILSEQ;
   127                 if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 8)
   137             err_ret("(%s) ERROR - wrong WAV header [format value]", prog);
   128                     *format = AL_FORMAT_STEREO8;
   138             return AL_FALSE;
   129                 else {
   139         }
   130                     if (ENDIAN_LITTLE_16(WAVHeader.BitsPerSample) == 16)
   140     }
   131                         *format = AL_FORMAT_STEREO16;
   141 
   132                     else {
   142     *bitsize = ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size);
   133                         errno = EILSEQ;
   143     *freq    = ENDIAN_LITTLE_32(WAVHeader.SampleRate);
   134                         err_ret("(%s) ERROR - wrong WAV header [bitsample value]", prog);
   144     return AL_TRUE;
   135                         return AL_FALSE;
   145 }
   136                     }				
   146 
   137                 }
   147 
   138             } else {
   148 int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) {
   139                 errno = EILSEQ;
   149     /*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */
   140                 err_ret("(%s) ERROR - wrong WAV header [format value]", prog); 
   150 
   141                 return AL_FALSE;
   151     /*ogg handle*/
   142             }
   152     FILE *oggFile;
   143         }
   153     /*stream handle*/
   144         
   154     OggVorbis_File oggStream;
   145         *bitsize = ENDIAN_LITTLE_32(WAVHeader.Subchunk2Size);
   155     /*some formatting data*/
   146         *freq    = ENDIAN_LITTLE_32(WAVHeader.SampleRate);
   156     vorbis_info *vorbisInfo;
   147         return AL_TRUE;
   157     /*length of the decoded data*/
   148     }
   158     int64_t pcm_length;
   149     
   159     /*other vars*/
   150     
   160     int section, result, size, endianness;
   151     int load_oggvorbis (const char *filename, ALenum *format, char **data, ALsizei *bitsize, ALsizei *freq) {
   161 #ifdef DEBUG
   152         /*implementation inspired from http://www.devmaster.net/forums/showthread.php?t=1153 */
   162     int i;
   153         
   163     /*other less useful data*/
   154         /*ogg handle*/
   164     vorbis_comment *vorbisComment;
   155         FILE *oggFile;
   165 #endif
   156         /*stream handle*/
   166 
   157         OggVorbis_File oggStream; 
   167     oggFile = Fopen(filename, "rb");
   158         /*some formatting data*/
   168     result = ov_open_callbacks(oggFile, &oggStream, NULL, 0, OV_CALLBACKS_DEFAULT);
   159         vorbis_info *vorbisInfo; 
   169     if (result < 0) {
   160         /*length of the decoded data*/
   170         errno = EINVAL;
   161         int64_t pcm_length;
   171         err_ret("(%s) ERROR - ov_fopen() failed with %X", prog, result);
   162         /*other vars*/
   172         ov_clear(&oggStream);
   163         int section, result, size, endianness;
   173         return -1;
   164 #ifdef DEBUG
   174     }
   165         int i;
   175 
   166         /*other less useful data*/
   176     /*load OGG header and determine the decoded data size*/
   167         vorbis_comment *vorbisComment;
   177     vorbisInfo = ov_info(&oggStream, -1);
   168 #endif
   178     pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels;
   169         
   179 
   170         oggFile = Fopen(filename, "rb");
   180 #ifdef DEBUG
   171         result = ov_open_callbacks(oggFile, &oggStream, NULL, 0, OV_CALLBACKS_DEFAULT);
   181     vorbisComment = ov_comment(&oggStream, -1);
   172         if (result < 0) {
   182     fprintf(stderr, "Version: %d\n", vorbisInfo->version);
   173             errno = EINVAL;
   183     fprintf(stderr, "Channels: %d\n", vorbisInfo->channels);
   174             err_ret("(%s) ERROR - ov_fopen() failed with %X", prog, result);
   184     fprintf(stderr, "Rate (Hz): %ld\n", vorbisInfo->rate);
       
   185     fprintf(stderr, "Bitrate Upper: %ld\n", vorbisInfo->bitrate_upper);
       
   186     fprintf(stderr, "Bitrate Nominal: %ld\n", vorbisInfo->bitrate_nominal);
       
   187     fprintf(stderr, "Bitrate Lower: %ld\n", vorbisInfo->bitrate_lower);
       
   188     fprintf(stderr, "Bitrate Windows: %ld\n", vorbisInfo->bitrate_window);
       
   189     fprintf(stderr, "Vendor: %s\n", vorbisComment->vendor);
       
   190     fprintf(stderr, "PCM data size: %lld\n", pcm_length);
       
   191     fprintf(stderr, "# comment: %d\n", vorbisComment->comments);
       
   192     for (i = 0; i < vorbisComment->comments; i++)
       
   193         fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]);
       
   194 #endif
       
   195 
       
   196     /*allocates enough room for the decoded data*/
       
   197     *data = (char*) Malloc (sizeof(char) * pcm_length);
       
   198 
       
   199     /*there *should* not be ogg at 8 bits*/
       
   200     if (vorbisInfo->channels == 1)
       
   201         *format = AL_FORMAT_MONO16;
       
   202     else {
       
   203         if (vorbisInfo->channels == 2)
       
   204             *format = AL_FORMAT_STEREO16;
       
   205         else {
       
   206             errno = EILSEQ;
       
   207             err_ret("(%s) ERROR - wrong OGG header [channel %d]", prog, vorbisInfo->channels);
   175             ov_clear(&oggStream);
   208             ov_clear(&oggStream);
   176             return -1;
   209             return -1;
   177         }
   210         }
   178         
   211     }
   179         /*load OGG header and determine the decoded data size*/
   212 
   180         vorbisInfo = ov_info(&oggStream, -1);
   213     size = 0;
   181         pcm_length = ov_pcm_total(&oggStream, -1) << vorbisInfo->channels;	
   214 #ifdef __LITTLE_ENDIAN__
   182         
   215     endianness = 0;
   183 #ifdef DEBUG
   216 #elif __BIG_ENDIAN__
   184         vorbisComment = ov_comment(&oggStream, -1);
   217     endianness = 1;
   185         fprintf(stderr, "Version: %d\n", vorbisInfo->version);
   218 #endif
   186         fprintf(stderr, "Channels: %d\n", vorbisInfo->channels);
   219     while (size < pcm_length) {
   187         fprintf(stderr, "Rate (Hz): %ld\n", vorbisInfo->rate);
   220         /*ov_read decodes the ogg stream and storse the pcm in data*/
   188         fprintf(stderr, "Bitrate Upper: %ld\n", vorbisInfo->bitrate_upper);
   221         result = ov_read (&oggStream, *data + size, pcm_length - size, endianness, 2, 1, &section);
   189         fprintf(stderr, "Bitrate Nominal: %ld\n", vorbisInfo->bitrate_nominal);
   222         if (result > 0) {
   190         fprintf(stderr, "Bitrate Lower: %ld\n", vorbisInfo->bitrate_lower);
   223             size += result;
   191         fprintf(stderr, "Bitrate Windows: %ld\n", vorbisInfo->bitrate_window);
   224         } else {
   192         fprintf(stderr, "Vendor: %s\n", vorbisComment->vendor);
   225             if (result == 0)
   193         fprintf(stderr, "PCM data size: %lld\n", pcm_length);
   226                 break;
   194         fprintf(stderr, "# comment: %d\n", vorbisComment->comments);
       
   195         for (i = 0; i < vorbisComment->comments; i++)
       
   196             fprintf(stderr, "\tComment %d: %s\n", i, vorbisComment->user_comments[i]);
       
   197 #endif
       
   198         
       
   199         /*allocates enough room for the decoded data*/
       
   200         *data = (char*) Malloc (sizeof(char) * pcm_length);
       
   201         
       
   202         /*there *should* not be ogg at 8 bits*/
       
   203         if (vorbisInfo->channels == 1)
       
   204             *format = AL_FORMAT_MONO16;
       
   205         else {
       
   206             if (vorbisInfo->channels == 2)
       
   207                 *format = AL_FORMAT_STEREO16;
       
   208             else {
   227             else {
   209                 errno = EILSEQ;
   228                 errno = EILSEQ;
   210                 err_ret("(%s) ERROR - wrong OGG header [channel %d]", prog, vorbisInfo->channels);
   229                 err_ret("(%s) ERROR - End of file from OGG stream", prog);
   211                 ov_clear(&oggStream);
   230                 ov_clear(&oggStream);
   212                 return -1;
   231                 return -1;
   213             }
   232             }
   214         }
   233         }
   215         
   234     }
   216         size = 0;
   235 
   217 #ifdef __LITTLE_ENDIAN__
   236     /*set the last fields*/
   218         endianness = 0;
   237     *bitsize = size;
   219 #elif __BIG_ENDIAN__
   238     *freq = vorbisInfo->rate;
   220         endianness = 1;
   239 
   221 #endif
   240     /*cleaning time (ov_clear also closes file handler)*/
   222         while (size < pcm_length) {
   241     ov_clear(&oggStream);
   223             /*ov_read decodes the ogg stream and storse the pcm in data*/
   242 
   224             result = ov_read (&oggStream, *data + size, pcm_length - size, endianness, 2, 1, &section);
   243     return 0;
   225             if (result > 0) {
       
   226                 size += result;
       
   227             } else {
       
   228                 if (result == 0)
       
   229                     break;
       
   230                 else { 
       
   231                     errno = EILSEQ;
       
   232                     err_ret("(%s) ERROR - End of file from OGG stream", prog);
       
   233                     ov_clear(&oggStream);
       
   234                     return -1;
       
   235                 }
       
   236             }
       
   237         }
       
   238         
       
   239         /*set the last fields*/
       
   240         *bitsize = size;
       
   241         *freq = vorbisInfo->rate;
       
   242         
       
   243         /*cleaning time (ov_clear also closes file handler)*/
       
   244         ov_clear(&oggStream);
       
   245 
       
   246         return 0;
       
   247     }
       
   248     
       
   249 #ifdef __CPLUSPLUS
       
   250 }
   244 }
   251 #endif