Posted: 10th Jun 2007 23:24
Hello all. I'm planning on making a little game where you can write your own songs using the Xbox 360 Guitar Hero II Controller. What I can't figure out is how to create a sound at a certain frequency. If someone could perhaps supply a dll that would make a chord when called that would be great.

Thanks in advance.
Posted: 11th Jun 2007 14:28
The commands you need are 'load sound', 'set sound speed', and 'play sound'. You don't need a dll to do what you're asking.
Posted: 11th Jun 2007 19:04
A few things to consider:
- Generating WAV sounds on the fly is tricky and probably won't sound like a guitar.
- Using MIDI will sound different depending upon the midi capabilities of the machine it will be run on and can sound very different to a real guitar on cheap sound hardware.
- Changing the pitch of a single WAV sample is easy but might not give a proper guitar sound if the pitch changed too much (if that is what you are after).
- The best results would be by sampling each string/note and storing it as a separate WAV sound. Then just play the one you want. It takes up more memory but you will get the best quality sound. Of course you can play more than one sound at once too to simulate chords.
Posted: 11th Jun 2007 21:08
I'd sample each string, then alter the pitch on each before playing them, so each string might be replayed at a different pitch to recreate a chord.
Posted: 11th Jun 2007 21:51
you can also use the SET SOUND SPEED command to alter the pitch. The faster the sound is, the higher the pitch.
Posted: 11th Jun 2007 23:00
and the shorter it plays for...
Posted: 12th Jun 2007 4:07
Can a frequency be generated from a memblock or something like that? I can get the frequencies of the notes and combine the notes to make a chord...
Posted: 12th Jun 2007 5:38
I don't know if this helps, but if you have a Creative sound card, they used to have an app called Keytar, I think. It was a guitar that you played with the keyboard, and it played chords. I know you can't see the source, but you might be able to see what kind of sound files they used. Also, good idea about sampling the individual strings. You could probably add lots of effects using that method, like bending strings and such.
Posted: 12th Jun 2007 5:46
This is what I use to make multi-frequency sounds. It works great. It can make complex sounds, but as has been pointed out it won't sound like a guitar without alot of help. It will make a chord if you use three frequencies in the signal array. You have to set the frequency, and delta. Delta is the frequency of the signal divided by the number of samples. Also you must set the volume.

+ Code Snippet
type SINUSOIDAL_WAVE
    fundamental as float            rem Frequency
    theta       as float            rem Instantaneous angle
    delta       as float            rem Incremental rotation
    amplitude   as float            rem Peak amplitude
endtype

dim signal() as SINUSOIDAL_WAVE

function GenerateSignal16(ptr as dword, numsamples as integer)
    local integrator as integer = 0
    local i as integer
    local j as integer
    local wtemp as word

    for i = 0 to numsamples - 1
        integrator = 0
        for j = 0 to array count(signal())
            inc integrator, int(sin(wrapvalue(signal(j).theta)) * ...
                                signal(j).amplitude)
            inc signal(j).theta, signal(j).delta
        next j
        wtemp = integrator
        *ptr = wtemp
        inc ptr, 2
    next i
endfunction

function WritePCMWaveFile(filename as string, wavedata_blk as integer, ...
                          size as integer)
    local i as integer
    local j as integer
    local k as integer
    local s2 as integer
    local ptr as dword

    ptr = get memblock ptr(wavedata_blk)
    s2 = size << 1
    if file exist(filename)
        delete file filename
    endif
    open to write 1, filename
    write byte 1, asc("R")
    write byte 1, asc("I")
    write byte 1, asc("F")
    write byte 1, asc("F")
    write long 1, s2 + 42
    write byte 1, asc("W")
    write byte 1, asc("A")
    write byte 1, asc("V")
    write byte 1, asc("E")
    write byte 1, asc("f")
    write byte 1, asc("m")
    write byte 1, asc("t")
    write byte 1, asc(" ")
    write long 1, 16
    write word 1, *ptr
    inc ptr, 4
    write word 1, *ptr
    inc ptr, 4
    write long 1, *ptr
    inc ptr, 4
    write long 1, *ptr
    inc ptr, 4
    write word 1, *ptr
    inc ptr, 4
    write word 1, *ptr
    inc ptr, 4
    write byte 1, asc("d")
    write byte 1, asc("a")
    write byte 1, asc("t")
    write byte 1, asc("a")
    write long 1, s2

    for k = 0 to size - 1
        write word 1, *ptr
        inc ptr, 2
    next k
    close file 1
endfunction


To use it, set the frequency (say, 440.0 for the note A), set theta to 0.0, calculate delta for the entire sample , and set the volume. (Volume can only equal 32767 total for 16 bit audio.)
Posted: 13th Jun 2007 5:42
I play guitar, so naturally when I saw the word GUITAR in the title for this I was like cool!, and if you want me to record some samples for you, I can easily do that. Just let me know, and tell me what sort of sound you would want (light blues versus extreme heavy metal). By the way, it would be really awesome to be able to plug the GH controller into your computer and play with it, that sounds like a really cool idea.
Posted: 13th Jun 2007 6:49
check out the code snippets (or 20-liner forget which) area too, as a while back a bunch of us had a go at making a sound editor only using memblocks.

turned out quite well too actually, should show you the structure to edit sounds.
Posted: 13th Jun 2007 9:28
Brain111, A sample of each string would be a great starting point, if you could do that then I'd certainly have a use for them, I think making a virtual guitar with just the string samples played at appropriate frequencies would be pretty good. You have to consider what sound trackers have to do, us a single guitar sample usually, with 5 strings playing individually it should be much better.
Posted: 14th Jun 2007 6:57
There's more to it than just sampling each string because each string has a total of 22 frets on it (for those of you who don't know much about guitars, they're the little lines you see dividing up the neck of the guitar.) Since the fifth fret of one string plays the same note as the next string without being fretted, except the gap between the G and B strings, which is 4 frets, a guitar in standard tuning can play a total of 46 pitches. Also, they have 6 strings, not 5, hahaha.


Ok, so before I can do this sampling, I need to know a few things:
*What type of tone do you want (clean, blues, rock, metal, etc...)
*How long do you want each note to last
*Would you rather have it in .WAV or .MP3 format?
Posted: 14th Jun 2007 9:27
*What type of tone do you want (clean, blues, rock, metal, etc...)
Metal would suit me fine.

*How long do you want each note to last
I think the best way would be to have a stab sample and a loop sample then control the volume of the loop to fade it out. Really as long as there's time for the stab bit to fade out and enough for a reasonable loop.

*Would you rather have it in .WAV or .MP3 format?
MP3's probably best for portability.


This is kinda experimental, but what I'm thinking is that if you can sample each string being strummed seperately, just as 1 long mp3 if you like. But my plan is that each string would have it's pitch changed to suit what fret it was on, then with a stab and loop setup, make a sorta virtual guitar.

There's a guitar toy coming out for the nintendo DS soon, like you have chords and you strum with the stylus, or even a pick if you like - but I'd love to make something like that. I'd share my coding efforts of course.
Posted: 14th Jun 2007 21:35
Ooohhhh I see, you're going to do like a pitch bend thing on the computer. If I only have to sample the 6 strings, that will be really fast, I'll do that right now as soon as I tune my guitar.
Posted: 14th Jun 2007 22:06
Here you go.
Posted: 14th Jun 2007 22:10
Perfect! - Thanks, is much appreciated.

Should get something cool done with them over the weekend.
Posted: 15th Jun 2007 3:37
Awesome, I'm glad to see I could help. I can't wait to see how this turns out.
Posted: 17th Jun 2007 1:25
also, at the 12th fret of each string, the notes repeat. mabey you could have just the notes up to the 12th fret pre-sampled, then if you are going any higher, raise the pitch and reuse the sounds. and some guitars have 7 strings, and some go up to the 24th fret (B.C Rich Warlock to name one). here are a few popular tunings: E-A-D-G-B-E (standard),D-A-D-G-B-E (dropped D),D-G-C-F-A-D (standard, one step down). For a 7 string guitar the standard tuning is B-E-A-D-G-B-e. possibly use clean samples, and simulate distortion, phasers, flangers, compressors, etc.. you will probably need 2 sets of samples, one for just regular notes, and one for palm muted notes, especially if you plan to simulate heavy metal. if you can simulate pitch alteration, harmonics would be an awesome addition. there are many different guitar techniques that would be hard to simulate, though not impossible. there is: palm muting, bending, slides (both up and down),legato slides (up & down), hammer ons, pull offs, harmonics (multiple types), tremolo picking, finger picking, and combinations of most of them.
Posted: 27th Jun 2007 6:56
How's this thing going, Van B?