Solved

Ogg Vorbis in Directsound - Access violation when locking and unlocking buffer

Posted on 2003-12-03
5
698 Views
Last Modified: 2007-12-19
I am implementing ogg support for my audio engine.  I have retrieved the ogg info using vorbis_info, and everything is okay.  When I got to lock (or unlock) the directsound buffer in order to read in the ogg data, I receive an access violation.  I can't find any reason why the following code doesn't work.

Any help would be much appreciated.

      pDS->CreateSoundBuffer( &desc, &pTemp, NULL );

      DWORD      size      =      BUFSIZE;
      DWORD      pos            =      0;
      int            sec            =      0;
      int            ret            =      1;

    char    *buf;
    char    *buf2;

   
      pTemp->Lock( 0, size, (LPVOID*)&buf, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
   
    // now read in the bits
    while(ret && pos<size)
    {
        ret = ov_read(&vf, buf+pos, size-pos, 0, 2, 1, &sec);
        pos += ret;
    }

    pTemp->Unlock( buf, size, NULL, NULL );

0
Comment
Question by:fearnsimon
  • 2
5 Comments
 
LVL 4

Expert Comment

by:void_main
ID: 9867095
Does it work with (for example) MP3 and WAV?
0
 

Author Comment

by:fearnsimon
ID: 9867845
I'm only trying to load .ogg files.  Have a separate class for .wav. Not using mp3.

I encode the .ogg file using cool edit 2 with the ogg i/o plugin. the ov_info function reads in all the info, but when I try to lock the DS buffer for writing, - ACCESS VIOLATION -

I'm using MS Visual Studio, DX SDK 8.1 (Debug), NV OpenGL SDK, and the Ogg Vorbis SDK if thats any help.
0
 
LVL 4

Accepted Solution

by:
void_main earned 500 total points
ID: 9872708
I am not a DirectX programmer (I am using BASS.DLL, which can play OGG, MP3, MP2.....) but I think you don't have any RAM allocated. Since I don't know how LOCK works exactly I suggest this:

in your code
//------------------------
 char    *buf;
 char    *buf2;

 pTemp->Lock( 0, size, (LPVOID*)&buf, &size, NULL, NULL, DSBLOCK_ENTIREBUFFER);
//------------------------
Lock tries to lock the buffer "buf" (or is this wrong), and when you create some variables local you have a -not defined-
value stored in them. My suggestions are
1st: I would set buf1 and buf2 to zero before use them.
2nd: If the 1st suggestion does not work you may add the next line between "char *buf2;"     and    "pTemp->Lock ....."
buf = new char[size];

I also can see that buf2 is never used (but I think you did not post your whole code.)

I hope that helped you, or gave an idea.

regards
void_main
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Artificial Intelligence comes in many forms, and for game developers, Path-Finding is an important ability for making an NPC (Non-Playable Character) maneuver through terrain.  A* is a particularly easy way to approach it.  I’ll start with the algor…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

820 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question