This site requires JavaScript, please enable it in your browser!
Greenfoot back
ronald
ronald wrote ...

2021/2/19

Button Sound Array

1
2
3
4
ronald ronald

2021/2/21

#
knowing that the song is in 16 bits, 44.1khz and a duration of 16 seconds for a size of 2.69 MB (2 826 496 bytes) 16 bits = 65536 values 16 bits = 2 bytes 2,826,496 bytes = 22,611,968 bits 22,611,986 bits / 16 bits = 1,413,248 bits 1413 248 bits * 65536 val = 92 618 620 928 values I don't know if this is what you want as values
ronald ronald

2021/2/21

#
long[] valFramesSong = new long[] {92618620928L,92618620928L,92618620928L,92618620928L,92618620928L};
skeptical about this code the numbers are huge
danpost danpost

2021/2/21

#
ronald wrote...
long[] valFramesSong = new long[] {92618620928L,92618620928L,92618620928L,92618620928L,92618620928L};
skeptical about this code the numbers are huge
I doubt those are frame counts per song. I also seriously doubt all 5 songs would run for exactly the same length of time. For a 4-minute song, you would get a value of only about 14400 (provided the scenario runs at normal speed).
ronald ronald

2021/2/21

#
the songs I had were huge in size about 30mb and therefore multiply by 5 I chose 5 such sounds, I know I can change afterwards. I had trouble finding a music album in its wav
danpost danpost

2021/2/22

#
ronald wrote...
the songs I had were huge in size about 30mb and therefore multiply by 5 I chose 5 such sounds, I know I can change afterwards. I had trouble finding a music album in its wav
But how long (in minutes and seconds) does each song play for?
ronald ronald

2021/2/22

#
currently 16 seconds each song before 3.22, 3.56, 2.59, 4.04 and 3.46 min.seconds
ronald ronald

2021/2/22

#
then 16 seconds = 960 values
danpost danpost

2021/2/22

#
ronald wrote...
then 16 seconds = 960 values
Correct (about that). You could get exact values by counting act steps a song plays for. Then plug those values into the array.
ronald ronald

2021/2/22

#
int[] valueSeconds = new int[] {960,960,960,960,960};
ronald ronald

4 days ago

#
public void act()
    {      
        for(int i = 0; i<buttons.length; i++)
        {           
        if(Greenfoot.mouseClicked(buttons[i]))
            {
            if(currentSong!=null) currentSong.stop();
            currentSong = new GreenfootSound(songs[i]);
            currentSong.play();
            
            while(i<=100)
            adjustValue(valueSeconds[i] - value);
            i++;
            repaint();
            }
        }        
    }
I added valuesconds a adjustvalue I know it's not good I try to do as (i - value) it is to reduce valuesconds a i It's just an idea, is this feasible? I do not know Maybe there is another way to do
danpost danpost

4 days ago

#
ronald wrote...
<< Code Omitted >> I added valuesconds a adjustvalue I know it's not good I try to do as (i - value) it is to reduce valuesconds a i It's just an idea, is this feasible? I do not know Maybe there is another way to do
You do not need an adjustValue for the int array. The int array values are not supposed to change. They represent the duration of the songs which do not change. You now need a single int field to track how long the current song has been playing. Set it to zero when a new song starts and increment it once per act as the song plays. Use the ratio of its value with the song duration to determine the value of the progress bar. I cannot say how exactly as you have not yet provided codes for bar.
ronald ronald

4 days ago

#
as I just put other different songs, do I have to make a table of seconds for each song length to be able to relate the value to the song length ???
danpost danpost

4 days ago

#
ronald wrote...
as I just put other different songs, do I have to make a table of seconds for each song length to be able to relate the value to the song length ???
You only need the valueSeconds array and the single int field for progress of current song. Just expand the array when you add more songs.
ronald ronald

4 days ago

#
danpost wrote...
I cannot say how exactly as you have not yet provided codes for bar.
I have no code of the progress bar It's always the same with AdjustValue and UpdatedDisplayValue your code if I understand correctly I have to redo a progress bar code For the value of the value and the duration of the song
ronald ronald

3 days ago

#
I do better by working with codes than with explanations can you give me a model?
There are more replies on the next page.
1
2
3
4