@@ -36,6 +36,7 @@ void Sound_game_static::playSoundTest(float gain)
3636{
3737 alSourceStop (p_hit_stream[0 ]);
3838 alSourceRewind (p_hit_stream[0 ]);
39+ alSourcei (p_hit_stream[0 ], AL_BUFFER, p_hit_sample[0 ]);
3940 alSourcef (p_hit_stream[0 ], AL_GAIN, 1.0 );
4041 alSourcef (p_hit_stream[0 ], AL_PITCH, 1.0 );
4142 alListenerf (AL_GAIN, gain);
@@ -66,12 +67,10 @@ void Sound_game_static::init()
6667 for (unsigned int i = 0 ; i != 4 ; ++i) {
6768 p_skid_stream[i] = createSource (p_skid_sample);
6869 }
69- for (int j = 0 ; j != 2 ; ++j)
70- for (int i = 0 ; i != hitStreamCount/2 ; ++i) {
71- p_hit_stream[i+j*(hitStreamCount/2 )] = createSource (p_hit_sample[j]);
72- }
73-
74- // p_test_stream = createSource(p_hit_sample[0]);
70+ for (int i = 0 ; i != hitStreamCount; ++i)
71+ {
72+ p_hit_stream[i] = createSource (0 );
73+ }
7574}
7675
7776void Sound_game_static::load (unsigned int i, ALbuffer engine0_sample, ALbuffer engine1_sample)
@@ -106,7 +105,6 @@ static constexpr float engine1_volume0 = 0.75f;
106105
107106void Sound_car::frame (float deltaT, int engine_state /* 0 - nultý, 1 - první, 2 - první potichu*/ , float engine_pitch, const float velocity[2 ])
108107{
109- //
110108 p_time += deltaT;
111109 if (p_time >= p_T) p_time = 0 .f ; else return ;
112110 if (!p_engine_on && engine_state == 2 )
@@ -216,9 +214,10 @@ void Sound_car::init(ALsource stream_engine, ALbuffer sample_idle, ALbuffer samp
216214 p_engine_on = 0 ;
217215}
218216
219- void Sound_crash::init (ALsource* stream_hit) // load zvuků
217+ void Sound_crash::init (const ALsource* stream_hit, const ALbuffer* sample_hit ) // load zvuků
220218{
221- p_hit_stream = stream_hit;
219+ p_hit_streams = stream_hit;
220+ p_hit_samples = sample_hit;
222221}
223222
224223void Sound_crash::play (float c_j) // přehraje zvuk nárazu
@@ -228,17 +227,19 @@ void Sound_crash::play(float c_j) // přehraje zvuk nárazu
228227 if (volume > 1 .f ) volume = 1 .f ;
229228 if (volume < 0 .f ) volume = 0 .f ;
230229 static const int sampleIndexer[6 ] = {0 , 1 , 0 , 1 , 0 , 1 };
231- int sample_sel =sampleIndexer[randn1 (5 )];
232- int stream_sel = p_fronta_pos[sample_sel]++;
233- p_fronta_pos[sample_sel] %= p_width;
234- int sel = stream_sel+sample_sel*p_width;
230+ int sample_sel = sampleIndexer[randn1 (5 )];
231+
232+ ALuint stream = p_hit_streams[p_currentStream];
235233
236- alSourceStop (p_hit_stream[sel]);
237- alSourceRewind (p_hit_stream[sel]);
238- alSourcef (p_hit_stream[sel], AL_GAIN, volume);
234+ alSourceStop (stream);
235+ alSourceRewind (stream);
236+ alSourcei (stream, AL_BUFFER, p_hit_samples[sample_sel]);
237+ alSourcef (stream, AL_GAIN, volume);
239238
240239 float pitch_min = 0.88 ;
241240 float pitch = pitch_min+randn1 (int ((1 .f -pitch_min)*2 .f *1000 .f ))*0.001 ;
242- alSourcef (p_hit_stream[sel], AL_PITCH, pitch);
243- alSourcePlay (p_hit_stream[sel]);
241+ alSourcef (stream, AL_PITCH, pitch);
242+ alSourcePlay (stream);
243+
244+ p_currentStream = (p_currentStream + 1 ) % Sound_game_static::hitStreamCount;
244245}
0 commit comments