Sound playback is muffled
Mark Sachs <[email protected]> Sun, 13 Jan 2013 15:19:26 -0500
| Newsgroups | gmane.comp.lib.openal |
|---|---|
| Message-ID | <CAGyii_c3CgaXFt-wEVoXHZkA_qqM1FGU0_z6hdkDGhA-RPxHPw@mail.gmail.com> |
--===============1502236281==
Content-Type: multipart/alternative; boundary=14dae93404f5c2a1dc04d3313eb6
--14dae93404f5c2a1dc04d3313eb6
Content-Type: text/plain; charset=ISO-8859-1
(Apologies for a possible double post: I tried to post first through
old.nabble.com's Web interface and it spit up a bunch of 500 errors.)
I'm trying to use OpenAL version 1.1 on Mac OSX Mountain Lion. I'm running
into a problem, though: a sound which plays back crisply in Audacity and
through OSX's Preview feature plays back muffled in my OpenAL code. It's as
if the sound fades in briefly at its start and then out at its end. No
unusual features of any kind are in use; I stripped everything down to a
minimal test program and it's still happening. I'm at a complete loss
here... anyone have any idea what's going on?
I've uploaded the sound in question to my web site at:
http://project-apollo.net/temp/shop_transact.wav
And here's the complete source code of the minimal playback program.
#include <unistd.h>
#include <iostream>
#include <vector>
using std::vector;
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
unsigned short ReadLE2(FILE* f)
{
unsigned char buffer[2];
fread(buffer, 2, 1, f);
return (buffer[1] << 8) + buffer[0];
}
uint ReadLE4(FILE* f)
{
unsigned char buffer[4];
fread(buffer, 4, 1, f);
return (buffer[3] << 24) + (buffer[2] << 16) + (buffer[1] << 8) +
buffer[0];
}
const char* ReadChunk4(FILE* f)
{
static char buffer[4];
if (fread(buffer, 4, 1, f) != 1)
return NULL; // EOF
return buffer;
}
bool CheckChunk4(FILE* f, const char* str)
{
const char* data = ReadChunk4(f);
return(strncmp(data, str, 4) == 0);
}
void Skip(FILE* f, uint bytes)
{
fseek(f, bytes, SEEK_CUR);
}
int main(int argc, const char * argv[])
{
ALCdevice* mDevice;
ALCcontext* mContext;
mDevice = alcOpenDevice("");
mContext = alcCreateContext(mDevice, NULL);
alcMakeContextCurrent(mContext);
ALuint mBuffer;
alGenBuffers(1, &mBuffer);
FILE* f = fopen("./shop_transact.wav", "rb");
// start reading chunks!
ALenum format;
ALsizei frequency;
vector<char> data;
while(1)
{
const char* chunkName = ReadChunk4(f);
if (!chunkName)
break;
if (strncmp(chunkName, "RIFF", 4) == 0)
{
// This is the RIFF type header.
Skip(f, 4); // Skip file size.
CheckChunk4(f, "WAVE");
continue;
}
if (strncmp(chunkName, "fmt ", 4) == 0)
{
// This is the format chunk.
uint dataSize = ReadLE4(f);
ReadLE2(f);
short channels = ReadLE2(f);
frequency = ReadLE4(f);
Skip(f, 4); // Skip BPS.
Skip(f, 2); // Skip block align.
short bits = ReadLE2(f);
if (channels == 1)
format = (bits == 8 ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16);
else
format = (bits == 8 ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16);
// Skip any extra data, though none should be present...
if (dataSize > 16)
Skip(f, dataSize - 16 + (dataSize % 2 == 1 ? 1 : 0));
continue;
}
if (strncmp(chunkName, "data", 4) == 0)
{
// This is the data chunk.
uint dataSize = ReadLE4(f);
data.resize(dataSize);
fread(&data[0], 1, dataSize, f);
if (dataSize % 2 == 1)
Skip(f, 1);
continue;
}
// Skip all other chunks.
uint dataSize = ReadLE4(f);
Skip(f, dataSize);
if (dataSize % 2 == 1)
Skip(f, 1);
}
fclose(f);
alBufferData(mBuffer, format, &data[0], (ALsizei)data.size(), frequency);
ALuint mSource;
alGenSources(1, &mSource);
alSourcei(mSource, AL_BUFFER, mBuffer);
std::cout << "Press a key to play the sound.\n";
while (1)
{
alSourcePlay(mSource);
if (getchar() == 'q')
{
alDeleteSources(0, &mSource);
alDeleteBuffers(0, &mBuffer);
alcDestroyContext(mContext);
alcCloseDevice(mDevice);
exit(0);
}
}
}
--
Mark Sachs
[email protected]
--14dae93404f5c2a1dc04d3313eb6
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div>(Apologies for a possible double post: I tried to pos=
t first through <a href=3D"http://old.nabble.com">old.nabble.com</a>'s =
Web interface and it spit up a bunch of 500 errors.)</div><div><br></div><d=
iv>
I'm trying to use OpenAL version 1.1 on Mac OSX Mountain Lion. I'm =
running into a problem, though: a sound which plays back crisply in Audacit=
y and through OSX's Preview feature plays back muffled in my OpenAL cod=
e. It's as if the sound fades in briefly at its start and then out at i=
ts end. No unusual features of any kind are in use; I stripped everything d=
own to a minimal test program and it's still happening. I'm at a co=
mplete loss here... anyone have any idea what's going on?</div>
<div><br></div><div>I've uploaded the sound in question to my web site =
at: <a href=3D"http://project-apollo.net/temp/shop_transact.wav">http://pro=
ject-apollo.net/temp/shop_transact.wav</a></div><div><br></div><div>And her=
e's the complete source code of the minimal playback program.</div>
<div><br></div><div><br></div><div><br></div><div>#include <unistd.h>=
</div><div>#include <iostream></div><div>#include <vector></div=
><div><br></div><div>using std::vector;</div><div><br></div><div>#include &=
lt;OpenAL/al.h></div>
<div>#include <OpenAL/alc.h></div><div><br></div><div>unsigned short =
ReadLE2(FILE* f)</div><div>{</div><div>=A0 =A0 unsigned char buffer[2];</di=
v><div>=A0 =A0 fread(buffer, 2, 1, f);</div><div>=A0 =A0 return (buffer[1] =
<< 8) + buffer[0];</div>
<div>}</div><div><br></div><div>uint ReadLE4(FILE* f)</div><div>{</div><div=
>=A0 =A0 unsigned char buffer[4];</div><div>=A0 =A0 fread(buffer, 4, 1, f);=
</div><div>=A0 =A0 return (buffer[3] << 24) + (buffer[2] << 16)=
+ (buffer[1] << 8) + buffer[0];</div>
<div>}</div><div><br></div><div>const char* ReadChunk4(FILE* f)</div><div>{=
</div><div>=A0 =A0 static char buffer[4];</div><div>=A0 =A0 if (fread(buffe=
r, 4, 1, f) !=3D 1)</div><div>=A0 =A0 =A0 =A0 return NULL;<span class=3D"" =
style=3D"white-space:pre"> </span>// EOF</div>
<div>=A0 =A0 return buffer;</div><div>}</div><div><br></div><div>bool Check=
Chunk4(FILE* f, const char* str)</div><div>{</div><div>=A0 =A0 const char* =
data =3D ReadChunk4(f);</div><div>=A0 =A0 return(strncmp(data, str, 4) =3D=
=3D 0);</div><div>
}</div><div><br></div><div>void Skip(FILE* f, uint bytes)</div><div>{</div>=
<div>=A0 =A0 fseek(f, bytes, SEEK_CUR);</div><div>}</div><div><br></div><di=
v><br></div><div>int main(int argc, const char * argv[])</div><div>{</div><=
div>
=A0 =A0 ALCdevice* mDevice;</div><div><span class=3D"" style=3D"white-space=
:pre"> </span>ALCcontext* mContext;</div><div>=A0 =A0=A0</div><div>=A0 =A0 =
mDevice =3D alcOpenDevice("");</div><div>=A0 =A0 mContext =3D alc=
CreateContext(mDevice, NULL);</div>
<div>=A0 =A0 alcMakeContextCurrent(mContext);</div><div>=A0 =A0=A0</div><di=
v>=A0 =A0=A0</div><div>=A0 =A0 ALuint mBuffer;</div><div>=A0 =A0=A0</div><d=
iv>=A0 =A0 alGenBuffers(1, &mBuffer);</div><div>=A0 =A0=A0</div><div><s=
pan class=3D"" style=3D"white-space:pre"> </span>FILE* f =3D fopen("./=
shop_transact.wav", "rb");</div>
<div><span class=3D"" style=3D"white-space:pre"> </span></div><div><span cl=
ass=3D"" style=3D"white-space:pre"> </span>// start reading chunks!</div><d=
iv><span class=3D"" style=3D"white-space:pre"> </span>ALenum format;</div><=
div><span class=3D"" style=3D"white-space:pre"> </span>ALsizei frequency;</=
div>
<div><span class=3D"" style=3D"white-space:pre"> </span>vector<char> =
data;</div><div><span class=3D"" style=3D"white-space:pre"> </span></div><d=
iv><span class=3D"" style=3D"white-space:pre"> </span>while(1)</div><div><s=
pan class=3D"" style=3D"white-space:pre"> </span>{</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>const char* chunkN=
ame =3D ReadChunk4(f);</div><div><span class=3D"" style=3D"white-space:pre"=
> </span>if (!chunkName)</div><div><span class=3D"" style=3D"white-space:p=
re"> </span>break;</div>
<div>=A0 =A0 =A0 =A0=A0</div><div><span class=3D"" style=3D"white-space:pre=
"> </span>if (strncmp(chunkName, "RIFF", 4) =3D=3D 0)</div><div>=
<span class=3D"" style=3D"white-space:pre"> </span>{</div><div><span class=
=3D"" style=3D"white-space:pre"> </span>// This is the RIFF type header.<=
/div>
<div><span class=3D"" style=3D"white-space:pre"> </span>Skip(f, 4);<span =
class=3D"" style=3D"white-space:pre"> </span>// Skip file size.</div><div><=
span class=3D"" style=3D"white-space:pre"> </span>CheckChunk4(f, "WA=
VE");</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>continue;</div><d=
iv><span class=3D"" style=3D"white-space:pre"> </span>}</div><div><span cl=
ass=3D"" style=3D"white-space:pre"> </span></div><div><span class=3D"" sty=
le=3D"white-space:pre"> </span>if (strncmp(chunkName, "fmt ", 4)=
=3D=3D 0)</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>{</div><div><span =
class=3D"" style=3D"white-space:pre"> </span>// This is the format chunk.=
</div><div><span class=3D"" style=3D"white-space:pre"> </span>uint dataSi=
ze =3D ReadLE4(f);</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>ReadLE2(f);</div>=
<div><span class=3D"" style=3D"white-space:pre"> </span>short channels =
=3D ReadLE2(f);</div><div><span class=3D"" style=3D"white-space:pre"> </s=
pan>frequency =3D ReadLE4(f);</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>Skip(f, 4); // Sk=
ip BPS.</div><div><span class=3D"" style=3D"white-space:pre"> </span>Skip=
(f, 2);<span class=3D"" style=3D"white-space:pre"> </span>// Skip block ali=
gn.</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>short bits =3D Re=
adLE2(f);</div><div><span class=3D"" style=3D"white-space:pre"> </span>if=
(channels =3D=3D 1)</div><div><span class=3D"" style=3D"white-space:pre"> =
</span>format =3D (bits =3D=3D 8 ? AL_FORMAT_MONO8 : AL_FORMAT_MONO16);<=
/div>
<div><span class=3D"" style=3D"white-space:pre"> </span>else</div><div><s=
pan class=3D"" style=3D"white-space:pre"> </span>format =3D (bits =3D=3D=
8 ? AL_FORMAT_STEREO8 : AL_FORMAT_STEREO16);</div><div><span class=3D"" st=
yle=3D"white-space:pre"> </span></div>
<div><span class=3D"" style=3D"white-space:pre"> </span>// Skip any extra=
data, though none should be present...</div><div><span class=3D"" style=3D=
"white-space:pre"> </span>if (dataSize > 16)</div><div><span class=3D"=
" style=3D"white-space:pre"> </span>Skip(f, dataSize - 16 + (dataSize % =
2 =3D=3D 1 ? 1 : 0));</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>continue;</div><d=
iv><span class=3D"" style=3D"white-space:pre"> </span>}</div><div><span cl=
ass=3D"" style=3D"white-space:pre"> </span></div><div><span class=3D"" sty=
le=3D"white-space:pre"> </span>if (strncmp(chunkName, "data", 4)=
=3D=3D 0)</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>{</div><div><span =
class=3D"" style=3D"white-space:pre"> </span>// This is the data chunk.</=
div><div><span class=3D"" style=3D"white-space:pre"> </span>uint dataSize=
=3D ReadLE4(f);</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>data.resize(dataS=
ize);</div><div><span class=3D"" style=3D"white-space:pre"> </span>fread(=
&data[0], 1, dataSize, f);</div><div><span class=3D"" style=3D"white-sp=
ace:pre"> </span>if (dataSize % 2 =3D=3D 1)</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>Skip(f, 1);</div=
><div><span class=3D"" style=3D"white-space:pre"> </span>continue;</div><=
div><span class=3D"" style=3D"white-space:pre"> </span>}</div><div><span c=
lass=3D"" style=3D"white-space:pre"> </span></div>
<div><span class=3D"" style=3D"white-space:pre"> </span>// Skip all other =
chunks.</div><div><span class=3D"" style=3D"white-space:pre"> </span>uint =
dataSize =3D ReadLE4(f);</div><div><span class=3D"" style=3D"white-space:pr=
e"> </span>Skip(f, dataSize);</div>
<div><span class=3D"" style=3D"white-space:pre"> </span>if (dataSize % 2 =
=3D=3D 1)</div><div><span class=3D"" style=3D"white-space:pre"> </span>Sk=
ip(f, 1);</div><div><span class=3D"" style=3D"white-space:pre"> </span>}</d=
iv><div>=A0 =A0=A0</div>
<div>=A0 =A0 fclose(f);</div><div><span class=3D"" style=3D"white-space:pre=
"> </span></div><div><span class=3D"" style=3D"white-space:pre"> </span>alB=
ufferData(mBuffer, format, &data[0], (ALsizei)data.size(), frequency);<=
/div><div>
=A0 =A0=A0</div><div>=A0 =A0=A0</div><div>=A0 =A0 ALuint mSource;</div><div=
>=A0 =A0=A0</div><div>=A0 =A0 alGenSources(1, &mSource);</div><div>=A0 =
=A0=A0</div><div>=A0 =A0 alSourcei(mSource, AL_BUFFER, mBuffer);</div><div>=
<br></div><div>=A0 =A0=A0</div><div>=A0 =A0 std::cout << "Press =
a key to play the sound.\n";</div>
<div>=A0 =A0 while (1)</div><div>=A0 =A0 {</div><div>=A0 =A0 =A0 =A0 alSour=
cePlay(mSource);</div><div>=A0 =A0 =A0 =A0 if (getchar() =3D=3D 'q'=
)</div><div>=A0 =A0 =A0 =A0 {</div><div>=A0 =A0 =A0 =A0 =A0 =A0 alDeleteSou=
rces(0, &mSource);</div><div>=A0 =A0 =A0 =A0 =A0 =A0 alDeleteBuffers(0,=
&mBuffer);</div>
<div>=A0 =A0 =A0 =A0 =A0 =A0 alcDestroyContext(mContext);</div><div>=A0 =A0=
=A0 =A0 =A0 =A0 alcCloseDevice(mDevice);</div><div>=A0 =A0 =A0 =A0 =A0 =A0=
exit(0);</div><div>=A0 =A0 =A0 =A0 }</div><div>=A0 =A0 }</div><div>}</div>=
<div><br></div><br>--<br>Mark Sachs<br><a href=3D"mailto:markbriansachs@gma=
il.com">[email protected]</a>
</div>
--14dae93404f5c2a1dc04d3313eb6--
--===============1502236281==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Openal mailing list
[email protected]
http://opensource.creative.com/mailman/listinfo/openal
--===============1502236281==--