HVScrollView
HVScrollView copied to clipboard
测试一个放美团的demo,拉到底部会跳动
您好,我测试了一个美团的demo,并且也用到了项目中,只是没有上下拉刷新,泥浆上下拉刷新去掉之后,将每一个cell的高度随机设置,我随便写到 arc4random()%300 + 100;这样你拉到底部,触发弹性效果的时候,松手会突然的回弹跳动,体验十分的不好,(如果没有重现,多拉几次,或者拉的距离大点就会出现)没有系统默认的那种回弹舒服,麻烦是否可以修复下上面的问题呢
Do you mean the size in bytes? Or the length in the number of audio samples? :)
Hello there again, Mr. Adam Stark
Sorry for the late reply. I have a Wave Sound file of 21,846 bytes (21.3 KB), length of some microseconds and BitRate of 1411 kbps, based on Properties window. After I load the file, I try to check the properties of the audio file based on your library, BitDepth(16), SampleRate(44100), Channel(2), Samples(5408), I try to get the buffer size by multiplying Channel and Samples = 10816. Following is how I load the audio file and create the audio buffer to be used with OpenAL Soft. Am I doing it correctly?
// load AudioFile<double>
ALuint buffer;
alGenBuffers((ALuint)1, &buffer);
int bufferSize = numChannel * numSamples;
double* bufferData = (double*)malloc(bufferSize);
alBufferData(buffer, AL_FORMAT_STEREO16, bufferData, bufferSize, sampleRate);
Edit:
The problem with the current code is the sound is played but I think only 1/4 part of the file was played. I think something is wrong with the way I count the bufferSize
.
I'm afraid I'm not familiar with OpenAL Soft - is the AudioFile library being used here? :)
Did he managed to load a file into openal? I'm having the same difficulty opening the file with AudioFile and loading it to openal
For those in the future looking to use this to pass PCM data to OpenAL.
It appears this library doesn't provide a function directly to get the PCM data, but it does do this work -- just for a different purpose. In the process of writing to a WAV file it writes the data in PCM in correct format. see "bool AudioFile<T>::saveToWaveFile" function. the DATA chunk portion.
I extracted this out into its own function
/** @note extracted this from writing to WAV file -- this is not part of the original library. */
template <class T>
bool AudioFile<T>::savePCMToBuffer(std::vector<uint8_t>& fileData)
{
fileData.clear();
int16_t audioFormat = bitDepth == 32 ? WavAudioFormat::IEEEFloat : WavAudioFormat::PCM;
for (int i = 0; i < getNumSamplesPerChannel(); i++)
{
for (int channel = 0; channel < getNumChannels(); channel++)
{
if (bitDepth == 8)
{
uint8_t byte = sampleToSingleByte(samples[channel][i]);
fileData.push_back(byte);
}
else if (bitDepth == 16)
{
int16_t sampleAsInt = sampleToSixteenBitInt(samples[channel][i]);
addInt16ToFileData(fileData, sampleAsInt);
}
else if (bitDepth == 24)
{
int32_t sampleAsIntAgain = (int32_t)(samples[channel][i] * (T)8388608.);
uint8_t bytes[3];
bytes[2] = (uint8_t)(sampleAsIntAgain >> 16) & 0xFF;
bytes[1] = (uint8_t)(sampleAsIntAgain >> 8) & 0xFF;
bytes[0] = (uint8_t)sampleAsIntAgain & 0xFF;
fileData.push_back(bytes[0]);
fileData.push_back(bytes[1]);
fileData.push_back(bytes[2]);
}
else if (bitDepth == 32)
{
int32_t sampleAsInt;
if (audioFormat == WavAudioFormat::IEEEFloat)
sampleAsInt = (int32_t) reinterpret_cast<int32_t&> (samples[channel][i]);
else // assume PCM
sampleAsInt = (int32_t)(samples[channel][i] * std::numeric_limits<int32_t>::max());
addInt32ToFileData(fileData, sampleAsInt, Endianness::LittleEndian);
}
else
{
assert(false && "Trying to write a file with unsupported bit depth");
return false;
}
}
}
return true;
}
basically converted this example to use AudioFIile, it is roughly below but may be missing some peices https://github.com/radiilab/3D-sound/blob/master/openal-example.c
It looks something like this
AudioFile<float> audioFile;
audioFile.load("sounds/TestSound.wav"))
ALuint buffer;
alGenBuffers(1, &buffer);
std::vector<uint8_t> pcmData_uint8;
audioFile.savePCMToBuffer(pcmData_uint8);
alBufferData(buffer, getALFormat(audioFile.getNumChannels(), audioFile.getBitDepth()),
/*bufferData*/ reinterpret_cast<ALvoid*>(pcmData_uint8.data()), pcmData_uint8.size(), audioFile.getSampleRate());
OpenAL expects the size in bytes.
This correctly played the sounds for me.
alListener3f(AL_POSITION, 0, 0, 1.0f);
alListener3f(AL_VELOCITY, 0, 0, 0);
alListenerfv(AL_ORIENTATION, listenerOri);
alGenSources((ALuint)1, &source);
alSourcef(source, AL_PITCH, 1);
alSourcef(source, AL_GAIN, 1);
alSource3f(source, AL_POSITION, 0, 0, 0);
alSource3f(source, AL_VELOCITY, 0, 0, 0);
alSourcei(source, AL_LOOPING, AL_FALSE);
alSourcei(source, AL_BUFFER, buffer);
alSourcePlay(source);
alGetSourcei(source, AL_SOURCE_STATE, &source_state);
while (source_state == AL_PLAYING) {
alGetSourcei(source, AL_SOURCE_STATE, &source_state);
}
You can see how to use AudilFile to get the data into a format for OpenAL.