6 OggVorbisStream::OggVorbisStream()
10 pthread_mutex_init(&vflock, 0);
13 OggVorbisStream::~OggVorbisStream()
18 bool OggVorbisStream::open(const char *fname)
22 pthread_mutex_lock(&vflock);
24 if(ov_fopen(fname, &vf) != 0) {
25 error_log("failed to open ogg/vorbis stream: %s\n", fname ? fname : "<not found>");
26 pthread_mutex_unlock(&vflock);
31 pthread_mutex_unlock(&vflock);
35 void OggVorbisStream::close()
37 pthread_mutex_lock(&vflock);
42 pthread_mutex_unlock(&vflock);
45 void OggVorbisStream::rewind()
47 pthread_mutex_lock(&vflock);
51 pthread_mutex_unlock(&vflock);
54 bool OggVorbisStream::more_samples(AudioStreamBuffer *buf)
56 pthread_mutex_lock(&vflock);
58 vorbis_info *vinfo = ov_info(&vf, -1);
59 buf->channels = vinfo->channels;
60 buf->sample_rate = vinfo->rate;
61 assert(buf->channels == 2);
62 assert(buf->sample_rate == 44100);
64 long bufsz = AUDIO_BUFFER_BYTES;
66 while(total_read < bufsz) {
68 long rd = ov_read(&vf, buf->samples + total_read, bufsz - total_read, 0, 2, 1, &bitstream);
79 pthread_mutex_unlock(&vflock);
83 buf->num_samples = bufsz / vinfo->channels / 2;
84 pthread_mutex_unlock(&vflock);