0
0

i am trying to use fmod with gtk but i have got a problem when i create a button of gtk to increase the volume or to stop the sound
could you help me or if you have got example it interest me
thanks

  • You must to post comments
0
0

[code:29eyf9wq]

// —————————————————–
// Make your button here
// I use a GtkAdjustment
//——————————————————

GtkWidget *volAdj, *scaleVol;

volAdj = GTK_ADJUSTMENT(gtk_adjustment_new (255, 0, 255, 0, 0, 0));
scaleVol = gtk_hscale_new ( volAdj );
gtk_widget_ref (scaleVol);
gtk_object_set_data_full (GTK_OBJECT (window1), "scaleVol", scaleVol,
(GtkDestroyNotify) gtk_widget_unref);
gtk_widget_show (scaleVol);
gtk_box_pack_start (GTK_BOX (hhbox), scaleVol, TRUE, TRUE, 80);
gtk_signal_connect(GTK_OBJECT(volAdj), "value_changed",
GTK_SIGNAL_FUNC(Update_Volume), NULL);

// ————————————————————–
// Signal func
// ————————————————————–
void Update_Volume (GtkAdjustment *adj)

{
FMUSIC_MODULE *mod;
FSOUND_STREAM *stream;
GtkAdjustment *adj1;

mod = song[songindex].mod;
stream = song[songindex].stream ;


if (mod) {
    FMUSIC_SetMasterVolume(mod, (int)adj->value);
    g_print("update volume = %d\n", volumechanged);
    volumechanged = 1;
   }
else if (stream) {
    FSOUND_SetVolume(song[songindex].channel, (int)adj->value);
 }

}

// —————————————————————
// I update the slider in a progress timeout (timer)
// —————————————————————
gboolean progress_timeout( gpointer data )
{

// Update the slider volume
gtk_adjustment_set_value(GTK_ADJUSTMENT(volAdj), (float)FMUSIC_GetMasterVolume(mod));
gtk_range_set_adjustment(GTK_RANGE(scaleVol), GTK_ADJUSTMENT(volAdj));
return TRUE;

}

[/code:29eyf9wq]

It is just some snippet from an unfinished gtk player i worked on a long time ago.[/code]

  • You must to post comments
0
0

i have send you a code but he ‘s got bugs so here a good code

[code:1pp1jpzl]

include<stdio.h>

include<string.h>

include "./fmod.h"

include <gtk/gtk.h>

extern int k=0;//volume du son

int a=0;

FSOUND_STREAM * stream;

int track(const char * file, FSOUND_STREAM * stream,int * channel)
{

if (((unsigned)FSOUND_Stream_GetLength(stream))>(FSOUND_Stream_GetPosition(stream )))
{
if((* channel)<0)
{
///le channel est libre on peut jouer:)))
*channel=FSOUND_Stream_PlayEx(FSOUND_FREE,stream,NULL,1);

  printf(&quot;%i\n&quot;,a);
  a++;
  if( k==1) FSOUND_SetVolume(*channel,200);
  else
    {
      if( k==2) FSOUND_SetVolume(*channel,150);
      else 
    {

      if( k==3) FSOUND_SetVolume(*channel,100);
      else 
        {
          if (k==4)  FSOUND_SetVolume(*channel,50);
          else
        {
          if (k==5)  FSOUND_SetVolume(*channel, 0);
          else 
            FSOUND_SetVolume(*channel,255);
        }
        }
    }
    }
  FSOUND_SetPaused(*channel,0);
}


} 

return 1;
}

int son (const char * file ){

int channel=-1;

FSOUND_SetOutput(FSOUND_OUTPUT_OSS);

FSOUND_SetDriver(0);// par defaut

///////////// initialisation //////////////

if (! FSOUND_Init(44100,32,0))
{
FSOUND_Close();
return 0;
}

//jouer

if(!( stream = FSOUND_Stream_OpenFile(file,FSOUND_NORMAL| FSOUND_MPEGACCURATE | FSOUND_LOOP_OFF,0)))return 0;

return( track(file,stream,&amp; channel));

}

[/code:1pp1jpzl]

and the main
[code:1pp1jpzl]

include<stdio.h>

include<gtk/gtk.h>

include “./fmod.h”

int k;
extern FSOUND_STREAM * stream;
void stop()
{

FSOUND_Close();
FSOUND_Stream_Close(stream);
}

void vol(GtkWidget * w){

k++;

}

void play(GtkWidget *w){
son(“./Les Bronzés font du ski.mp3”);
}

int main(int argc,char * argv[]){
GtkWidget * window;
GtkWidget *hbox;
GtkWidget * button_play;
GtkWidget * button_vol;
GtkWidget * button_stop;

gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
hbox=gtk_hbox_new(FALSE,0);
gtk_container_add(GTK_CONTAINER(window),hbox);

button_play = gtk_button_new_with_label(“play”);
gtk_signal_connect(GTK_OBJECT(button_play),”clicked”,GTK_SIGNAL_FUNC(play),NULL);
gtk_box_pack_start(GTK_BOX(hbox),button_play,TRUE,TRUE,0);
gtk_widget_show(button_play);

button_vol = gtk_button_new_with_label(“volume”);
gtk_signal_connect(GTK_OBJECT(button_vol),”clicked”,GTK_SIGNAL_FUNC(vol),NULL);
gtk_box_pack_start(GTK_BOX(hbox),button_vol,TRUE,TRUE,0);
gtk_widget_show(button_vol);

button_stop= gtk_button_new_with_label(“Stop”);
gtk_signal_connect(GTK_OBJECT(button_stop),”clicked”,GTK_SIGNAL_FUNC(stop),NULL);
gtk_box_pack_start(GTK_BOX(hbox),button_stop,TRUE,TRUE,0);
gtk_widget_show(button_stop);

gtk_widget_show(hbox);
gtk_widget_show(window);
gtk_main();
return 0;

}

[/code:1pp1jpzl]

i can now stop my sound but i can’t play again

thanks for help

  • You must to post comments
0
0

[code:15irjwbd]

include <stdio.h>

include <gtk/gtk.h>

include "./fmod.h"

FSOUND_STREAM *stream;
int channel;

void
Update_Volume (GtkAdjustment *adj)
{
if (stream && channel)
{
FSOUND_SetVolume(channel, (int)adj->value);
}

}

void
load_file(const char *m_file)
{

stream = FSOUND_Stream_OpenFile(m_file,FSOUND_NORMAL| FSOUND_MPEGACCURATE | FSOUND_LOOP_OFF,0);
}

int
init_sound()
{
// c’est juste pour moi, la flemme de switcher sous Linux pour tester :)

ifdef WIN32

FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);

else

FSOUND_SetOutput(FSOUND_OUTPUT_OSS);

endif

FSOUND_SetDriver(0); // par defaut

if (! FSOUND_Init(44100,32,0))
{
FSOUND_Close();
return -1;
}

return 1;
}

void
pause()
{
FSOUND_SetPaused(channel, !FSOUND_GetPaused(channel));
}

void
stop()
{
FSOUND_Stream_Close(stream);
FSOUND_Close();
}

void
play()
{

if (init_sound())
{
load_file("test.mp3");
if (stream)
channel=FSOUND_Stream_PlayEx(FSOUND_FREE,stream,NULL,1);
FSOUND_SetPaused(channel,0);
}
}

void
exit_app()
{
FSOUND_Close();
gtk_main_quit();
}

gboolean
on_window_destroy_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
exit_app();
return FALSE;
}

gboolean
on_window_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
exit_app();
return FALSE;
}

int main(int argc,char * argv[]){
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *button_play;
GtkWidget *button_vol;
GtkWidget *button_stop;

GtkWidget *table;
GtkAdjustment *volAdj;
GtkWidget *scaleVol, *lblVolume;
GtkWidget *hhbox, *vvbox;
GtkWidget *lblName;

gtk_init(&amp;argc,&amp;argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_object_set_data (GTK_OBJECT (window), &quot;window&quot;, window);
gtk_window_set_title (GTK_WINDOW (window), &quot;Player&quot;);

table = gtk_table_new(3,2,TRUE);
gtk_widget_show(table);
gtk_container_add(GTK_CONTAINER(window), table);

hbox=gtk_hbox_new(FALSE,0);

button_play = gtk_button_new_with_label(&quot;&gt;&quot;);
gtk_signal_connect(GTK_OBJECT(button_play),&quot;clicked&quot;,GTK_SIGNAL_FUNC(play),NULL);

button_vol = gtk_button_new_with_label(&quot;||&quot;);
gtk_signal_connect(GTK_OBJECT(button_vol),&quot;clicked&quot;,GTK_SIGNAL_FUNC(pause),NULL);

button_stop= gtk_button_new_with_label(&quot;&quot;);
gtk_signal_connect(GTK_OBJECT(button_stop),&quot;clicked&quot;,GTK_SIGNAL_FUNC(stop),NULL);

// ——————————————————————

hhbox = gtk_hbox_new (FALSE, 0);
gtk_widget_ref (hhbox);

volAdj = (GtkAdjustment *)(gtk_adjustment_new (255, 0, 255, 0, 0, 0));
scaleVol = gtk_hscale_new ( GTK_ADJUSTMENT(volAdj) );
gtk_widget_ref (scaleVol);
gtk_object_set_data_full (GTK_OBJECT (window), &quot;scaleVol&quot;, scaleVol,
                        (GtkDestroyNotify) gtk_widget_unref);

gtk_table_attach_defaults(GTK_TABLE(table), button_play, 0, 1, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), button_vol, 1, 2, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), button_stop, 2, 3, 0, 1);   
gtk_table_attach_defaults(GTK_TABLE(table), scaleVol, 0, 3, 1, 2);        

gtk_signal_connect(GTK_OBJECT(volAdj), &quot;value_changed&quot;,
GTK_SIGNAL_FUNC(Update_Volume),  NULL);


gtk_signal_connect (GTK_OBJECT (window), &quot;delete_event&quot;,
                  GTK_SIGNAL_FUNC (on_window_delete_event),
                  NULL);

gtk_signal_connect (GTK_OBJECT (window), &quot;destroy_event&quot;,
                  GTK_SIGNAL_FUNC (on_window_destroy_event),
                  NULL);

gtk_widget_show_all(window);                      
gtk_main();

return 0;
}
[/code:15irjwbd]

  • You must to post comments
0
0

merci ca va trop m’aider mais juste un truc ke j’arrive pas a regler aussi c’est le stop
j’ai f comme toi mais g le meme probleme des ke je veux relire il me plante totalement
y a pas un moyen de stopper le son et de recommencer une autre musique?

malo
ps : v le faire en anglais qd meme
et je voulais savoir si tu etais ds une ecole d’info?
moi perso je suis a epita en spé


in english
thanks
i help me a lot but i have got another problem
which is i can’t stop the sound.
i the same function of you which stop my sound but like you it bug.
how can i clear to play another sound?
malo

  • You must to post comments
0
0

(en anglais, désolé, ou ils vont pas aimer)
Hi ! If you want to play the next song when the current song reached the end, delete the FSOUND_Close() func from the Stop(). This ll resolve the crash :)
Ahem no, i am not a computer student, just a taught self guy (autodidacte) 😉
If you have other problems with fmod, don’t hesitate to contact me (pm, mail …) @ KarLKoX@ifrance.com

  • You must to post comments
0
0

thanks but it doesn’t work
i want to stop the sound and after to play it again
thanks to help me
malo

  • You must to post comments
0
0

weird … the above code works for me (under winxp/nt 4), here is another way to do that :

[code:3jve8ceu]

include <stdlib.h>

include <gtk/gtk.h>

include <glib.h>

include <fmod.h>

FSOUND_STREAM *stream;
int channel;

void
Update_Volume (GtkAdjustment *adj)
{
if (stream && channel)
{
FSOUND_SetVolume(channel, (int)adj->value);
}
}

void
load_file(const char *m_file)
{
stream = FSOUND_Stream_OpenFile(m_file,FSOUND_NORMAL| FSOUND_MPEGACCURATE | FSOUND_LOOP_OFF,0);
}

int
init_sound()
{
// c’est juste pour moi, la flemme de switcher sous Linux pour tester :)

ifdef WIN32

FSOUND_SetOutput(FSOUND_OUTPUT_DSOUND);

else

FSOUND_SetOutput(FSOUND_OUTPUT_OSS);

endif

FSOUND_SetDriver(0); // par defaut

if (! FSOUND_Init(44100,32,0))
{
FSOUND_Close();
return -1;
}
return 1;
}

void
pause()
{
FSOUND_SetPaused(channel, !FSOUND_GetPaused(channel));
}

void
stop()
{
FSOUND_Stream_Stop(stream);
}

void
play()
{
if (stream)
{
channel=FSOUND_Stream_PlayEx(FSOUND_FREE,stream,NULL,1);
FSOUND_SetPaused(channel,0);
}
}

void
exit_app()
{
if (stream)
{
FSOUND_Stream_Close(stream);
stream = NULL;
}
FSOUND_Close();
gtk_main_quit();
}

gboolean
on_window_destroy_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
exit_app();
return FALSE;
}

gboolean
on_window_delete_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
exit_app();
return FALSE;
}

int main(int argc,char * argv[]){
GtkWidget *window;
GtkWidget *hbox;
GtkWidget *button_play;
GtkWidget *button_vol;
GtkWidget *button_stop;

GtkWidget *table;
GtkAdjustment *volAdj;
GtkWidget *scaleVol, *lblVolume;
GtkWidget *hhbox, *vvbox;
GtkWidget *lblName;

gtk_init(&argc,&argv);
window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_object_set_data (GTK_OBJECT (window), "window", window);
gtk_window_set_title (GTK_WINDOW (window), "Player");

table = gtk_table_new(3,2,TRUE);
gtk_widget_show(table);
gtk_container_add(GTK_CONTAINER(window), table);

hbox=gtk_hbox_new(FALSE,0);

button_play = gtk_button_new_with_label(">");
gtk_signal_connect(GTK_OBJECT(button_play),"clicked",GTK_SIGNAL_FUNC(play),NULL);

button_vol = gtk_button_new_with_label("||");
gtk_signal_connect(GTK_OBJECT(button_vol),"clicked",GTK_SIGNAL_FUNC(pause),NULL);

button_stop= gtk_button_new_with_label("");
gtk_signal_connect(GTK_OBJECT(button_stop),"clicked",GTK_SIGNAL_FUNC(stop),NULL);

// ——————————————————————

hhbox = gtk_hbox_new (FALSE, 0);
gtk_widget_ref (hhbox);

volAdj = (GtkAdjustment *)(gtk_adjustment_new (255, 0, 255, 0, 0, 0));
scaleVol = gtk_hscale_new ( GTK_ADJUSTMENT(volAdj) );
gtk_widget_ref (scaleVol);
gtk_object_set_data_full (GTK_OBJECT (window), "scaleVol", scaleVol,
(GtkDestroyNotify) gtk_widget_unref);

gtk_table_attach_defaults(GTK_TABLE(table), button_play, 0, 1, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), button_vol, 1, 2, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), button_stop, 2, 3, 0, 1);
gtk_table_attach_defaults(GTK_TABLE(table), scaleVol, 0, 3, 1, 2);

gtk_signal_connect(GTK_OBJECT(volAdj), "value_changed",
GTK_SIGNAL_FUNC(Update_Volume), NULL);

gtk_signal_connect (GTK_OBJECT (window), "delete_event",
GTK_SIGNAL_FUNC (on_window_delete_event),
NULL);

gtk_signal_connect (GTK_OBJECT (window), "destroy_event",
GTK_SIGNAL_FUNC (on_window_destroy_event),
NULL);

if (init_sound())
load_file("test.mp3");
else {
printf("Sound Initialisation Error !\n");
exit_app();
}

gtk_widget_show_all(window);
gtk_main();

return 0;
}
[/code:3jve8ceu]

Here i preload the song, there is no time consuming when pressing the play button (the song was loaded each time i pressed it).

  • You must to post comments
0
0

thanks for all
it’s help me a lot
bye
malo

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.