int IAudioStream::GetStride() { SPADES_MARK_FUNCTION(); int stride; switch(GetSampleFormat()){ case UnsignedByte: stride = 1; break; case SignedShort: stride = 2; break; case SingleFloat: stride = 4; break; default: SPInvalidEnum("GetSampleFormat", GetSampleFormat()); } return stride * GetNumChannels(); }
/* Function: alureGetSampleFormat * * Retrieves an OpenAL format for the given sample format. If bits is non-0, * floatbits must be 0, and if floatbits is non-0, bits must be 0. The * application should not rely on any particular format enum being returned as * it is dependant on the available extensions. The returned format will be * valid for the current context. Requires an active context. * * Returns: * An OpenAL format enum for the given sample format, or AL_NONE if one can't * be found. */ ALURE_API ALenum ALURE_APIENTRY alureGetSampleFormat(ALuint channels, ALuint bits, ALuint floatbits) { if(alGetError() != AL_NO_ERROR) { SetError("Existing OpenAL error"); return AL_NONE; } if(bits && floatbits) { SetError("Both bit-types specified"); return AL_NONE; } if(bits) return GetSampleFormat(channels, bits, false); return GetSampleFormat(channels, floatbits, true); }
virtual bool GetFormat(ALenum *fmt, ALuint *frequency, ALuint *blockalign) { if(format == AL_NONE) format = GetSampleFormat(sndInfo.channels, 16, false); *fmt = format; *frequency = sndInfo.samplerate; *blockalign = sndInfo.channels*2; return true; }
aiffStream(std::istream *_fstream) : alureStream(_fstream), format(0), dataStart(0) { ALubyte buffer[25]; int length; if(!fstream->read(reinterpret_cast<char*>(buffer), 12) || memcmp(buffer, "FORM", 4) != 0 || memcmp(buffer+8, "AIFF", 4) != 0) return; while(!dataStart || format == AL_NONE) { char tag[4]; if(!fstream->read(tag, 4)) break; /* read chunk length */ length = read_be32(fstream); if(memcmp(tag, "COMM", 4) == 0 && length >= 18) { /* mono or stereo data */ channels = read_be16(fstream); /* number of sample frames */ fstream->ignore(4); /* bits per sample */ sampleSize = read_be16(fstream) / 8; /* sample frequency */ samplerate = read_be80extended(fstream); /* block alignment */ blockAlign = channels * sampleSize; format = GetSampleFormat(channels, sampleSize*8, false); length -= 18; } else if(memcmp(tag, "SSND", 4) == 0) { dataStart = fstream->tellg(); dataStart += 8; dataLen = remLen = length - 8; } fstream->seekg(length, std::ios_base::cur); } if(dataStart > 0 && format != AL_NONE) fstream->seekg(dataStart); }
virtual bool GetFormat(ALenum *fmt, ALuint *frequency, ALuint *blockalign) { if(format == AL_NONE) { format = GetSampleFormat(2, 32, true); if(format == AL_NONE) format = AL_FORMAT_STEREO16; } *fmt = format; *frequency = sampleRate; *blockalign = 2 * ((format==AL_FORMAT_STEREO16) ? sizeof(ALshort) : sizeof(ALfloat)); return true; }
int CBuzzSample::GetBitsPerSample() { switch (GetSampleFormat()) { case 0: return 16; case 1: return 32; case 2: return 32; case 3: return 24; default: return 16; } }
LAVAudioSampleFormat CLAVAudio::GetBestAvailableSampleFormat(LAVAudioSampleFormat inFormat, BOOL bNoFallback) { ASSERT(inFormat >= 0 && inFormat < SampleFormat_Bitstream); if (m_FallbackFormat != SampleFormat_None && !bNoFallback) return m_FallbackFormat; LAVAudioSampleFormat outFormat = sampleFormatMapping[inFormat][0]; for(int i = 0; i < 5; i++) { if (GetSampleFormat(sampleFormatMapping[inFormat][i])) { outFormat = sampleFormatMapping[inFormat][i]; break; } } return outFormat; }
wavStream(std::istream *_fstream) : alureStream(_fstream), format(0), dataStart(0) { ALubyte buffer[25]; ALuint length; if(!fstream->read(reinterpret_cast<char*>(buffer), 12) || memcmp(buffer, "RIFF", 4) != 0 || memcmp(buffer+8, "WAVE", 4) != 0) return; while(!dataStart || format == AL_NONE) { char tag[4]; if(!fstream->read(tag, 4)) break; /* read chunk length */ length = read_le32(fstream); if(memcmp(tag, "fmt ", 4) == 0 && length >= 16) { /* Data type (should be 1 for PCM data, 3 for float PCM data, * 7 for muLaw, and 17 for IMA4 data) */ int type = read_le16(fstream); if(type != 0x0001 && type != 0x0003 && type != 0x0007 && type != 0x0011) break; /* mono or stereo data */ channels = read_le16(fstream); /* sample frequency */ samplerate = read_le32(fstream); /* skip average bytes per second */ fstream->ignore(4); /* bytes per block */ blockAlign = read_le16(fstream); if(blockAlign == 0) break; /* bits per sample */ sampleSize = read_le16(fstream); length -= 16; /* Look for any extra data and try to find the format */ ALuint extrabytes = 0; if(length >= 2) { extrabytes = read_le16(fstream); length -= 2; } extrabytes = std::min<ALuint>(extrabytes, length); if(type == 0x0001) format = GetSampleFormat(channels, sampleSize, false); else if(type == 0x0003) format = GetSampleFormat(channels, sampleSize, true); else if(type == 0x0007) { if(sampleSize == 8) { if(channels == 1) format = AL_FORMAT_MONO_MULAW; else if(channels == 2) format = AL_FORMAT_STEREO_MULAW; else if(channels == 4) format = AL_FORMAT_QUAD_MULAW; else if(channels == 6) format = AL_FORMAT_51CHN_MULAW; else if(channels == 7) format = AL_FORMAT_61CHN_MULAW; else if(channels == 8) format = AL_FORMAT_71CHN_MULAW; } } else if(type == 0x0011 && extrabytes >= 2) { int samples = read_le16(fstream); length -= 2; /* AL_EXT_IMA4 only supports 36 bytes-per-channel block * alignment, which has 65 uncompressed sample frames */ if(blockAlign == 36*channels && samples == 65*channels && alIsExtensionPresent("AL_EXT_IMA4")) { if(channels == 1) format = AL_FORMAT_MONO_IMA4; else if(channels == 2) format = AL_FORMAT_STEREO_IMA4; } } } else if(memcmp(tag, "data", 4) == 0) { dataStart = fstream->tellg(); dataLen = remLen = length; } fstream->seekg(length, std::ios_base::cur); } if(dataStart > 0 && format != AL_NONE) fstream->seekg(dataStart); }