mirror of
https://github.com/bloeys/wavy.git
synced 2025-12-29 09:28:19 +00:00
Sound info+sound time+remaining time
This commit is contained in:
37
wavy_test.go
37
wavy_test.go
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user