3

I have a problem with playing generated sine audio signal, using an Android API AudioTrack object. Everything works great while the amplitude of the sine signal is above around 40 ( maximum possible amplitude value is 36535 due to the 16 bit PCM format ), but when I set the amplitude below 40, no sound is played unless I change the volume level with the side up-down buttons (doesn't matter if I change it up or down).

Even this way the sound only appears for a second and disappears again and it should last 10 seconds. I'm having this issue on SGS 2. I suspect that the problem is due to some limitation in the core of the OS and maybe it considers this low signal like noise.

I would appreciate if someone has an idea of what the problem might be and give me some directions how to fix it.

tshepang
  • 12,111
  • 21
  • 91
  • 136
eNeLOu
  • 31
  • 2

1 Answers1

0

I have a similar problem. In My App I have to play silent at the start (sine wave amplitude is 0), and then, after 2 seconds I play sine wave with amplitude = 10000.

However sometimes, even I start playing AudioTrack (static mode, stream is MUSIC), I hear nothing, and only after I change volume manually I start hearing my sounds. Before playing any sounds (even silent), I programmatically set stream volume to max, and control output volume by signal amplitude.

Have you figured out the reason of this?

Update:

Diving into issue more deeply I found strange thing, while device is in this weird state, my calls to AudioManager.setStreamVolume doesn't work. I checked this:

int max = mAudioManager.getStreamMaxVolume(SoundConfig.outputStreamType); // max = 15
int v = mAudioManager.getStreamVolume(SoundConfig.outputStreamType); // v = 0
mAudioManager.setStreamVolume(SoundConfig.outputStreamType, max, 0); 
v = mAudioManager.getStreamVolume(SoundConfig.outputStreamType); // v = 0

After this I started to analyze logcat output, what I found is: - in the weird state setting up volume and starting playback looks like:

12-19 12:45:37.120: D/AudioService(192): getStreamVolume(12)  
12-19 12:45:40.970: D/AudioSystem(192): getParameters() ERROR : can't get parameters  
12-19 12:45:40.970: D/AudioService(192): getStreamVolume(12)  
12-19 12:45:45.680: D/AudioService(192): getStreamVolume(12)  
12-19 12:45:50.120: I/AudioPolicyManager(110): startOutput() output 1, stream 3, session 6  
12-19 12:45:50.120: I/AudioPolicyManager(110): getDeviceForStrategy() strategy 0, device 4  
12-19 12:45:50.120: I/AudioPolicyManager(110): getDeviceForStrategy() strategy 0, device 4  
12-19 12:45:50.120: I/AudioFlinger(110): start output streamType (0, 3) for 1  
12-19 12:45:50.120: D/AudioHardware(110): AudioStreamOutALSA::setParameters() start_output_streamtype=3  
12-19 15:25:02.521: D/AudioHardware(110): AudioHardware pcm playback is exiting standby.  

But in normal state (after I pressed volume buttons up and down) it looks like:

12-19 15:25:02.481: D/AudioSystem(193): getParameters() ERROR : can't get parameters  
12-19 15:25:02.481: D/AudioService(193): getStreamVolume(12)  
12-19 15:25:02.481: I/AudioService(193):  AudioFocus  abandonAudioFocus() from  android.media.AudioManager#413cbf68com.kinsa.manager.CAndroidManager#414087a0  
12-19 15:25:02.491: I/AudioService(193):  AudioFocus  requestAudioFocus() from android.media.AudioManager#413cbf68com.kinsa.manager.CAndroidManager#414087a0  
12-19 15:25:02.491: D/AudioSystem(193): getParameters() ERROR : can't get parameters  
12-19 15:25:02.491: D/AudioHardware(110): AudioStreamOutALSA::setParameters() music_volume_index=1  
12-19 15:25:02.491: D/AudioService(193): getStreamVolume(12)  
12-19 15:25:02.491: D/AudioService(193): getStreamVolume(12)  
12-19 15:25:02.491: D/AudioService(193): getStreamVolume(12)  
12-19 15:25:02.491: D/AudioSystem(193): getParameters() ERROR : can't get parameters  
12-19 15:25:02.501: D/AudioService(193): getStreamVolume(12)  
12-19 15:25:02.501: D/AudioService(193): getStreamVolume(12)  
12-19 15:25:02.501: D/AudioService(193): getStreamVolume(12)  
12-19 15:25:02.501: D/AudioHardware(110): AudioStreamOutALSA::setParameters() music_volume_index=15  
12-19 15:25:02.521: I/AudioPolicyManager(110): startOutput() output 1, stream 3, session 3  
12-19 15:25:02.521: I/AudioPolicyManager(110): getDeviceForStrategy() strategy 0, device 4  
12-19 15:25:02.521: I/AudioPolicyManager(110): getDeviceForStrategy() strategy 0, device 4  
12-19 15:25:02.521: I/AudioFlinger(110): start output streamType (0, 3) for 1  
12-19 15:25:02.521: D/AudioHardware(110): AudioStreamOutALSA::setParameters() start_output_streamtype=3  
12-19 15:25:02.521: D/AudioHardware(110): AudioHardware pcm playback is exiting standby.  

In the second case I see how hardware set volume to max, and then exits standby state, but it doesn't happen in the first case. But why? The same code, the only difference is executing it after pressing volume buttons in the second case.

user2041064
  • 131
  • 7