Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
Vorbis
Vorbis
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 0
    • Merge Requests 0
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • Wiki
    • Wiki
  • Members
    • Members
  • Collapse sidebar
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
  • Xiph.Org
  • VorbisVorbis
  • Issues
  • #7

Closed
Open
Opened Mar 08, 2001 by cmeinhardt@cmeinhardt

Vorbis decode example code fails to produce valid pcm data if not stereo

The code in decoder_example.c works fine as long as one does not decode audio 
data that has been encoded from a non stereo source.

The original code in the decoder_example.c file looks like this:

for(i=0;i<vi.channels;i++){
  ogg_int16_t *ptr=convbuffer+i;
  float  *mono=pcm[i];
  for(j=0;j<bout;j++){
    int val=mono[j]*32767.f;
    if(val>32767){val=32767; clipflag=1;}
    if(val<-32768){val=-32768; clipflag=1;}
    *ptr=val;
    ptr+=2;
  }
}

This works just fine on stereo. ptr is set to the right interleaved start 
address. But in the following loop ptr should fill all samples on one channel. 
So ptr is incremented to jump over the other channels. Here's the bug
in the original code, ptr+=2 is hardcoded for stereo output.

Without hardcoding, here's the working code:

for(i=0;i<vi.channels;i++){
  ogg_int16_t *ptr=convbuffer+i;
  float  *mono=pcm[i];
  for(j=0;j<bout;j++){
    int val=mono[j]*32767.f;
    if(val>32767){val=32767; clipflag=1;}
    if(val<-32768){val=-32768; clipflag=1;}
    *ptr=val;
    ptr+=vi.channels;
  }
}

I have tested it on several audio sources, its all working. But I have not 
tested it on >2 channel audio sources. I believe it should work, but no proof 
from me...

>8) Best regards

Christian Meinhardt
Neuland Multimedia GmbH
www.neulandmm.de
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: xiph/vorbis#7