Sound info+sound time+remaining time

This commit is contained in:
bloeys
2022-06-18 13:26:28 +04:00
parent dd0c21efc7
commit a0af1959e0
2 changed files with 133 additions and 12 deletions

View File

@ -100,33 +100,60 @@ func NewSineWave(freq float64, duration time.Duration) *SineWave {
func TestSound(t *testing.T) {
audioFPath := "./test_audio_files/Fatiha.mp3"
fatihaFilepath := "./test_audio_files/Fatiha.mp3"
const fatihaLenMS = 55484
//Streaming
s, err := wavy.NewSoundStreaming(audioFPath, wavy.SampleRate_44100, wavy.SoundChannelCount_2, wavy.SoundBitDepth_2)
s, err := wavy.NewSoundStreaming(fatihaFilepath, wavy.SampleRate_44100, wavy.SoundChannelCount_2, wavy.SoundBitDepth_2)
if err != nil {
t.Errorf("Failed to load new sound with path '%s'. Err: %s\n", audioFPath, err)
t.Errorf("Failed to load streaming sound with path '%s'. Err: %s\n", fatihaFilepath, err)
return
}
s.PlayAsync()
time.Sleep(1 * time.Second)
remTime := s.RemainingTime()
if remTime.Milliseconds() >= fatihaLenMS-900 {
t.Errorf("Expected time to be < %dms but got %dms in streaming sound\n", fatihaLenMS-900, remTime.Milliseconds())
return
}
if err := s.Close(); err != nil {
t.Errorf("Closing streaming sound failed. Err: %s\n", err)
return
}
totalTime := s.TotalTime()
if totalTime.Milliseconds() != fatihaLenMS {
t.Errorf("Expected time to be %dms but got %dms in streaming sound\n", fatihaLenMS, totalTime.Milliseconds())
return
}
//In-Memory
s, err = wavy.NewSoundMem(audioFPath, wavy.SampleRate_44100, wavy.SoundChannelCount_2, wavy.SoundBitDepth_2)
s, err = wavy.NewSoundMem(fatihaFilepath, wavy.SampleRate_44100, wavy.SoundChannelCount_2, wavy.SoundBitDepth_2)
if err != nil {
t.Errorf("Failed to load new sound with path '%s'. Err: %s\n", audioFPath, err)
t.Errorf("Failed to load memory sound with path '%s'. Err: %s\n", fatihaFilepath, err)
return
}
s.PlayAsync()
time.Sleep(1 * time.Second)
remTime = s.RemainingTime()
if remTime.Milliseconds() >= fatihaLenMS-900 {
t.Errorf("Expected time to be < %dms but got %dms in memory sound\n", fatihaLenMS-900, remTime.Milliseconds())
return
}
if err := s.Close(); err != nil {
t.Errorf("Closing in-memory sound failed. Err: %s\n", err)
return
}
totalTime = s.TotalTime()
if totalTime.Milliseconds() != fatihaLenMS {
t.Errorf("Expected time to be %dms but got %dms in memory sound\n", fatihaLenMS, totalTime.Milliseconds())
return
}
}