seeking error

View: New views
1 Messages — Rating Filter:   Alert me  

seeking error

by cab-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


rob wrote :
Sadeesh Kumar wrote:
> In libmad, when the song is playing, how can i jump to different
> differnt location and start to play from that location?. I find it, there is
> no direct easy interface to do this.

To jump to a new location using the low-level API:

  1. Seek to an approximate location in the file and load your buffer with
     data from the new position.

  2. Call mad_stream_buffer() to update the stream pointers for the modified
     buffer.

  3. Call mad_frame_mute() and mad_synth_mute().

At this point you can simply resume decoding. However, to avoid any unpleasant
burps in the audio, unless you have seeked to the very beginning of the file,
it is best to:

  4. Call mad_frame_decode() successfully at least twice. Note that the
     first few calls will probably yield recoverable decoding errors which
     you can safely ignore.

  5. Call mad_synth_frame() once and discard the resulting PCM.

The MAD plug-in for Winamp does all of this if you're looking for an example.

Cheers,
  -rob



but the problem is

I've got these errors
decoding error 0x0101 (lost synchronization) at byte offset 4096
decoding error 0x0235 (bad main_data_begin pointer) at byte offset 4203


and then my player doesn't work any more, there's a bug

what is wrong ? here my source code
int seek(state*status /*structure to store the data*/,int value)
{
printf("seeking  in mp3 started\n");
        struct mad_stream *stream;
                stream=status->stream;
        struct mad_frame frame;
                frame=status->mad_frame;
        struct mad_synth synth;
                synth=status->synth;
        printf("%lf is the value in percent\n",value);
        pthread_mutex_lock(&mutex);
        int seek_bit;
        int bitrate=status->bitrate;
        int samplerate=status->srate;
        int frame_size=144*bitrate/samplerate;
        seek_bit=percent_to_bits(status->mp3_file_size,(int)value);
        int reste=seek_bit-status->cur_bit;
        int factor=reste/frame_size;
        seek_bit=status->cur_bit+factor*frame_size+4*factor;
        printf("mad stream buffer call\n");
        mad_stream_buffer(stream,status->start_mp3+seek_bit,status->mp3_file_size-seek_bit);
        status->cur_bit=seek_bit;
        mad_frame_mute(&frame);
        mad_synth_mute(&synth);
        int result,i=0;
        result=mad_frame_decode(&frame,stream);
        while((result!=0)||(i<2))
        {
                result=mad_frame_decode(&frame,stream);
                i+=1;
        }
        mad_synth_frame(&synth,&frame);
        pthread_mutex_unlock(&mutex);
        printf("seeking in mp3 ended\n");
        return 0;

}


what is wrong with my source code?
LightInTheBox - Buy quality products at wholesale price