Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Audio storage, stereo switching
#11
If I understand correctly, you want to encode data into sound. Well, it could probably work. What do you need for that? You need to encode 256 different frequencies, each representing one byte. Now it depends on what byte rate you want to use for that. And also if the FFT will read it. The FFT is very accurate so it should read it. Let's say you want to encode at a frequency of 150 Hz in steps of 50 Hz, so byte 255 will be at a frequency of 12900 Hz. For that, you need a sampling frequency of at least 25000 Hz (that's fine). To fully modulate the 50 Hz oscillation, you will need: 1) sample time t = 1 / f so 1 / 50 = 0.02 seconds, number of samples = t * _SndRate = 0.02 * 44100 = 882 samples.

So the higher the sound frequency you choose, the faster the data reading will be, but only theoretically, it also depends a lot on how exactly the FFT can parse it. Instead of the checksum used in files, in this case I would rather be motivated by network operation, where you first send a signal to the other party (starting a data block), it will be fixed at 256 bytes (so it will wait for 256 frequencies), after receiving it, the other party confirms that the data has been received, their sum is sent for checking and the process is repeated. It follows that the program that reads data from the sound must decode the first block, it will be something like a file header, where there will be a description of how many blocks are being sent. then it will be read and finally the sum is performed to see if the length of the data in the block agrees with what was declared. That then depends on how you will operate it. But in general, even sending data using a walkie-talkie is very slow. If the sound is distorted, the transmission must be repeated, it is not suitable for long distances. It depends on the power used and the radio band.

Interesting idea, this. I would simply do it like when you write a program to store images. One program stores the data, another displays it. This will be the same. One program takes a set of bytes, assigns a frequency to each byte, and modulates the signal accordingly. For functionality tests, skip the data transfer and write a second program that takes the stored data and analyzes it back and decomposes it into bytes.

You modulate the signal as a Sine with a given frequency, save the sound data in a binary file, you don't even have to use WAV for this. The second program opens the data file and converts it back to data. If this works, the only question is what the distortion will be during transmission in practice.

To transfer data between two computers in the form of sound, you will need a good quality microphone, or connect the SPK output of one computer to the LineIn of the other computer with a cable. But here we run into a problem, because so far I don't know of anything in QB64PE that can record sound from LineIn. It is probably necessary to use winmm.dll, but I currently don't have a program that can communicate with LineIn.


Reply
#12
Easy example. Volume leve is used as byte indicator.


Code: (Select All)

ReDim Shared CodedSound(0) As Single

CodeSnd "Hi this is text example, this time volume level is used as byte - modulation. This maybe can be good between two computers, but not good for radio signal."

For i = 1 To UBound(CodedSound)
    _SndRaw CodedSound(i)
Next i

Print EncodeSnd



Sub CodeSnd (Text As String)
    ReDim CodedSound(Len(Text) * 100) As Single
    Dim As Long I, L, G
    SignalDuration = 100 'one signal amplitude lenght is 100 samples
    stp = 1 / 256
    For L = 1 To Len(Text)
        For G = 1 To 100
            CodedSound(I) = Asc(Text, L) * stp
            I = I + 1
        Next G
    Next L
End Sub

Function EncodeSnd$
    Dim As Long i, g, j
    Dim As Single s
    stp = 1 / 256
    For i = 1 To (UBound(CodedSound) \ 100)
        s = 0
        For g = i To i + 99
            s = s + CodedSound(j)
            j = j + 1
        Next g
        s = (s / 100) * 256
        e$ = e$ + Chr$(s)
    Next i
    EncodeSnd$ = e$
End Function


Reply




Users browsing this thread: 2 Guest(s)