Me and @HEXcellerate briefly discussed in the Lounge whether saving a song as a trigonometric function instead of saving it as a sequence of frequencies and magnitudes would save hard drive space. So I found a website http://www.math.umn.edu/~rogness/math1155/soundwaves/ which briefly touches upon this topic but I was not able to find anything tangible that could support this.
So I kind of tested this assumption on a small scale
I downloaded two .wav files from the website linked previously.
1. a.wav 7.9K 1 second duration
2. a_csharp_and_e.wav 7.9K 1 second duration
Then from the website I took the corresponding functions and saved them separately as plain files.
1. aFunction with contents
sin(880Pi * x) 15 bytes
2. a_csharp_and_eFunction with contents
'sin(880Pi * x) + sin(1100Pi * x) + sin(1320Pi * x)' 51 bytes
As expected the functions took up less space.
And I was wondering, since our computers become more and more advanced, could we just save up on space by representing the track as a trigonometric function and then let the program solve the function by plugging in time for x and represent the value as sound?
While the test that I did might be very far from being conclusive I just can't help myself but think about this topic. If I had more programming experience and I could represent a .wav file as a function I would do it. The solver is definitely not an issue. Do you guys have any input regarding this topic? I would love to know if there is any knowledge we could bring up for discussion.
Sorry if I this does not belong in this category I was split between audio and code.
I was recently thinking about the same thing, but with images and videos. Files could describe functions that represent the color variations through images, instead of storing independent data for every single pixel in every frame.
I dont know how video compression works, though. Might work like this already, might work with a way better idea.
From my very ignorant perspective, this looks like it is easier for computers to interpret and reproduce from.
Well video compression works by cutting each frame into chunks and then trying to find any patterns that could help save space. But to be honest I don't know how you could describe an image as a function. But I agree that in theory it would just be more efficient for a computer to interpret the function as it is solving it rather than reading each value and interpreting each frequency, magnitude etc.
It's an interesting topic. So I guess it would be some kind of analog audio compression. If I understand correctly, the final result would be a file with a series of instructions saying which functions to generate, in which frequency, amplitude and duration, instead of a stream of bits organized in a certain format.
As for videos, I know there's a kind of encoding that instead of sending each frame to be displayed in sequence, only the variations of colours for each pixel are sent, along with a "occasional" synchronization frame. Only the changed pixels would be processed, ignoring the unchanged ones. This would mean that if you have a video with each pixel changing from black to white in each frame, the end result of the compression would be really close to the original file. Similarly, a video with only one colour of frame would be greatly compressed.
I sort of see how there could have something similar with sound. Specifying the duration of each frequency to be generated and not altering the process until needed. Although it's practically impossible to have a audio file with few variations on frequency, amplitude and tone. Tone in the sense that you can tell the difference between a piano sound, a guitar sound, a voice sound and so on. These functions would get really complex for having different "shapes" and these shapes would generally be an ideally infinite combination of simpler functions themselves, getting closer to the desired shape with the more functions you have.
Alternatively, there could be pre-defined libraries that would ease the processing of these "infinite" functions, like having a square wave function or triangle function, instead of basing every signal in sine waves, which would certainly result in loss of quality. Maybe this way, the whole idea could be possible, but for storage purposes. I don't think it would be worth processing the whole thing on the go. Therefore, to extract the audio file, some sort of compilation would be involved.
It's been a long time since I had my signal processing lectures, so anyone feel free to correct me in anything.
.jpg is kinda works like a function.
Yeah, so I wonder how complex these functions can get until the storage taken becomes greater than regular compression.
I will look up some sources on how it works because I am not familiar with how it compresses.
Each of those squares are a formula that describes how its going to look as a whole, rather than describing each pixel.
This formula calculates the value of the chunks of the pictures. The actual file looks like this
what I am actually thinking of is this
Its probably better to do such with sound than images.
If you can store a waveform as a formula instead of all that amplitude stuff It could probably save space, maybe.
Writing something that can look at a waveform and find the closest one to a formula is going to be pretty hard though.
My idea with images was this:
Take a table relating each pixel of an image to it's color.
pixel 1 : Color 3129
pixel 2 : Color 32854
pixel 3 : Color 2330
Then assigning every pixel to a number between 0 and 2Pi.
Then there should be a trigonometric function, that relates each pixel to it's corresponding color, in this form :
I think the process of finding this function is called trigonometric interpolation. There probably are methods for this that could be used to make a very efficient file compression algorithm.
So I have 0 background in math or music, but I'm thinking you could do this pretty simply at the low level. There's plenty of space to be saved by not doing it in plain text, If I know what I was getting into, I could probably get that space down even further than 51 byte...probably in the realm of 20...
0x00 0x0370 0x00 0x044c 0x00 0x0528 (18 bytes)
Again, no background AT ALL in math or music, but if they're all sin/cos/tan representations, and they all use Pi and x as values, it'd be very simple to write a codec for this.
My next project. Make an interpolator for the function that will describe the song and a decoder that will solve the function for time and play the frequencies
The main issue behind turning a waveform into a formula is that you can't turn a waveform directly into a formula.
Since its analog you have to find the closest approximation that fits the bill closest, and I don't see how you can do that without some AI like code.
The neat thing about formula based compression would be that its technically analog in a way instead of digital.
And you also need to convert it to digital again if you want to play it with a normal sound card, since they're digital devices.
The numbers that define how the waveform should look also need to be capped at a certain number, you're going end up with a limited amount of waveforms.
I wouldn't be surprised if it has already been tried with audio.