Tôi đang sử dụng khung âm thanh OpenAL trên iPhone và tôi đang đặt âm lượng khác nhau trên từng âm thanh. Tôi đang gặp một vấn đề khi tôi nghe thấy tiếng ồn khi bật/bấm ban đầu khi chuyển từ âm này sang âm thanh khác.Âm thanh lạ khi phát các âm thanh khác nhau với các âm lượng khác nhau được đặt thông qua OpenAL trên iPhone
Nó thực sự đáng chú ý khi tôi có một âm thanh có âm lượng cao (1.0) và âm thanh thứ hai có âm lượng thấp (0.2). Khi tôi nhấn âm thanh lớn, và sau đó nhấn âm thanh mềm, tôi nghe thấy tiếng pop/click. Nhưng khi tôi đi từ âm thanh mềm đến lớn, tôi không nhận thấy bất cứ điều gì. Vì vậy, các pop/click thực sự xảy ra khi chuyển từ âm thanh lớn sang âm thanh mềm.
Dưới đây là phương pháp âm thanh init:
- (id) initWithSoundFile:(NSString *)file doesLoop:(BOOL)loops
{
self = [super init];
if (self != nil)
{
if(![self loadSoundFile:file doesLoop:loops])
{
debug(@"Failed to load the sound file: %@...", file);
[self release];
return nil;
}
self.sourceFileName = file;
//temporary sound queue
self.temporarySounds = [NSMutableArray array];
//default volume/pitch
self.volume = 1.0;
self.pitch = 1.0;
}
return self;
}
và đây là chức năng chơi:
- (BOOL) play
{
if([self isPlaying]) //see if the base source is busy...
{
//if so, create a new source
NSUInteger tmpSourceID;
alGenSources(1, &tmpSourceID);
//attach the buffer to the source
alSourcei(tmpSourceID, AL_BUFFER, bufferID);
alSourcePlay(tmpSourceID);
//add the sound id to the play queue so we can dispose of it later
[temporarySounds addObject: [NSNumber numberWithUnsignedInteger:tmpSourceID]];
//a "callback" for when the sound is done playing +0.1 secs
[self performSelector:@selector(deleteTemporarySource)
withObject:nil
afterDelay:(duration * pitch) + 0.1];
return ((error = alGetError()) != AL_NO_ERROR);
}
//if the base source isn't busy, just use that one...
alSourcePlay(sourceID);
return ((error = alGetError()) != AL_NO_ERROR);
}
và đây là chức năng nơi mà tôi đặt âm lượng cho mỗi âm thanh ngay lập tức sau khi chơi (ive cố gắng thiết lập nó trước khi chơi quá):
- (void) setVolume:(ALfloat)newVolume
{
volume = MAX(MIN(newVolume, 1.0f), 0.0f); //cap to 0-1
alSourcef(sourceID, AL_GAIN, volume);
//now set the volume for any temporary sounds...
for(NSNumber *tmpSourceID in temporarySounds)
{
//tmpSourceID is the source ID for the temporary sound
alSourcef([tmpSourceID unsignedIntegerValue], AL_GAIN, volume);
}
}
Bất kỳ trợ giúp nào được đánh giá cao như tôi đã thử rất nhiều điều tôi có thể nghĩ đến. Tôi cảm thấy vô cùng biết ơn.
Điều đó cũng xảy ra trên Mac. Bạn đã tìm thấy giải pháp chưa? –
@Quakeboy - Không, tôi không có, tôi đã từ bỏ nó. Cùng một vấn đề với thiết lập pitch âm thanh cá nhân. – c0dec0de