consolidate all repos to one for archive
This commit is contained in:
68
semester_5/racunalniska_vecpredstavnost/vaja_3/main.cpp
Normal file
68
semester_5/racunalniska_vecpredstavnost/vaja_3/main.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
#define NIKOLA_UTILS_IMPLEMENTATION
|
||||
#include "utils.hpp"
|
||||
|
||||
#include "Compressor.hpp"
|
||||
#include "Decompressor.hpp"
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
if (argc <= 2)
|
||||
{
|
||||
printf("Usage: %s <1|2>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (std::atoi(argv[1]) == 1)
|
||||
{
|
||||
if (argc != 6)
|
||||
{
|
||||
printf("Usage: %s 1 <input.wav> <block size> <window size> <output.bin>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
|
||||
sf::SoundBuffer buffer;
|
||||
|
||||
if (!buffer.loadFromFile(argv[2]))
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
std::size_t sampleCount = buffer.getSampleCount();
|
||||
const sf::Int16 *samples_p = buffer.getSamples();
|
||||
Compressor compressor;
|
||||
compressor.compress(samples_p, sampleCount, std::atoi(argv[3]), std::atoi(argv[4]), argv[5]);
|
||||
printf("compressed\n");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (argc != 4)
|
||||
{
|
||||
printf("Usage: %s 2 <input.bin> <output.wav>\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
Decompressor decompressor;
|
||||
std::vector<signed short> out = decompressor.decompress(argv[2]);
|
||||
|
||||
sf::SoundBuffer buffer2;
|
||||
buffer2.loadFromSamples(&out[0], out.size(), 2, 44100);
|
||||
buffer2.saveToFile(argv[3]);
|
||||
sf::Sound sound(buffer2);
|
||||
|
||||
sound.play();
|
||||
while (sound.getStatus() == sf::Sound::Playing)
|
||||
{
|
||||
sf::sleep(sf::milliseconds(1000));
|
||||
sf::Time t = sound.getPlayingOffset();
|
||||
printf("\rplaying offset: %f", t.asSeconds());
|
||||
fflush(stdout);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user