Thread concurrency (OpenGL vs STK)
	
	
		Bonjour :D
J'ai une animation (win32) OpenGL à laquelle j'essaie d'intégrer de la synthese sonore avec la lib STK.(au passage, si vous connaissez 'mieux' ...mais qui tourne sous windows ;) )
Mon problème vient du fait que le rendu graphique via une fonction glut:
main.cpp : 
	Code:
	
| 12
 3
 4
 5
 6
 7
 
 | int main()
{
...
glutReshapeFunc(ReshapeCallback_1);
glutDisplayFunc(RenderCallback_1);
...
} | 
 est bloqué pendant le calcul du son: 
attack.cpp:
	Code:
	
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 
 | int Attack::tick( void *outputBuffer, void *inputBuffer, unsigned int nBufferFrames,
         double streamTime, RtAudioStreamStatus status, void *dataPointer )
{
  SineWave *sine = (SineWave *) dataPointer;
  register StkFloat *samples = (StkFloat *) outputBuffer;
 
  for ( unsigned int i=0; i<nBufferFrames; i++ )
    *samples++ = sine->tick();
 
  return 1;
}
//--------------------------------------------------------------------------------------------------------
bool Attack::play()
{
 
 
   SineWave sine;
 
  //- Figure out how many bytes in an StkFloat and setup the RtAudio stream.
  RtAudio::StreamParameters p;
  p.deviceId = dac.getDefaultOutputDevice();
  p.nChannels = 1;//_o_->channel;
  RtAudioFormat format = ( sizeof(StkFloat) == 8 ) ? RTAUDIO_FLOAT64 : RTAUDIO_FLOAT32;
 
  //-The bufferFrames argument is an API-dependent buffering parameter (see RtAudio for further information).
  unsigned int bufferFrames = RT_BUFFER_SIZE;//defined in Stk.h.
 
//--1) OPEN STREAM
  try {
 
	dac.openStream( &p,												//RtAudio::StreamParameters *outputParameters,
								NULL,											//RtAudio::StreamParameters *inputParameters,
								format,											// RtAudioFormat format, unsigned int sampleRate
								(unsigned int)Stk::sampleRate(), //unsigned int *bufferFrames
								&bufferFrames,							//RtAudioCallback callback, void *userData
								&Attack::tick,								//RtAudio::StreamOptions *options
								(void *)&sine 
								);
 }
 
  catch ( RtError &error ) {
    error.printMessage();
    goto cleanup;
  }
 
  sine.setFrequency( _o_->frequency );
 
  //--2) START STREAM
  try {
    dac.startStream();
}
  catch ( RtError &error ) {
    error.printMessage();
   goto cleanup;
 }
 
		cleanup:
 
		dac.closeStream();
		//delete dac;
		//_o_->func_killFM(_o_->id); 
} | 
 ... qui semble utiliser une thread , concept que je n'ai pas encore abordé.
Je suis donc parti d'un exemple  un Callback,dont une portion du code est en partie responsable du problème:
	Code:
	
| 12
 3
 4
 
 |   // Block waiting here.
 char keyhit;
  cout << "\nPlaying ... press <enter> to quit.\n";
  cin.get( keyhit ); | 
 
J'ai supprimé cette partie, pensant que le son continuerait à jouer mais cela provoque une erreur (error.printMessage() ) -que je n'arrive pas à afficher- puisque 
est aussitôt appelé !
Faudrait-il remplacer le code supprimé par autre chose ou bien est-ce la thread tick() qui pose problème... 
...sachant qu' Attack  est une classe pouvant avoir de multiples instances...
Que faire 8O ???
ps: On m'a suggéré de mettre un 
juste après startStream() , ou dans tick() 
... ou encore de m'intéresser au concept de concurrence !??