Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lab_2: Huffman. Kornienko Dimas #93

Open
wants to merge 34 commits into
base: ohorielov_lab_2
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
e9c4fb2
Lab1: wav processor
insouciiance Sep 23, 2022
029674a
review #1
insouciiance Oct 24, 2022
e5f03de
Merge pull request #60 from ohorielov/ohorielov_lab_2
ohorielov Dec 19, 2022
77ca230
* review fix #2
insouciiance Dec 21, 2022
c0b1cb2
- .project
insouciiance Dec 21, 2022
2455696
Add files via upload
beanomen4 Dec 22, 2022
3866237
Merge pull request #13 from insouciiance/IP-01_Kovalenko_Mykyta
ohorielov Dec 29, 2022
79b680e
Виправив код
artbyk Dec 16, 2022
64472f6
Lab_1: Changed wav file volume
bldddrn Dec 23, 2022
3c29b02
Lab_1: Add universal wav header reader
bldddrn Dec 30, 2022
f7aa43e
Lab_1: Fixed one bug
bldddrn Jan 4, 2023
deebc19
Lab_1
beanomen4 Jan 6, 2023
efc88d2
Lab_2 + Hoffman's algorithm, which I made by hand
beanomen4 Jan 6, 2023
70c9fe8
Create IA_03_Kutsyk_Mykola
MykolaKutsyk Jan 6, 2023
025919d
Delete IA_03_Kutsyk_Mykola
MykolaKutsyk Jan 6, 2023
70a8104
Update main.c
artbyk Jan 6, 2023
3218ea2
Update main.c
artbyk Jan 6, 2023
1e1228a
Revert "Lab_1"
beanomen4 Jan 6, 2023
c37e960
Revert "Lab_2 + Hoffman's algorithm, which I made by hand"
beanomen4 Jan 6, 2023
998f3f5
Revert "Merge pull request #65 from bldddrn/IA-03_Sharkovskyi_Volodymyr"
beanomen4 Jan 6, 2023
29120ac
Revert "Merge pull request #56 from artbyk/IO-04_Chornyi_Artem"
beanomen4 Jan 6, 2023
bcbb838
Revert "Merge branch 'ohorielov:develop' into develop"
beanomen4 Jan 6, 2023
5a6993d
Merge branch 'pr/77' into develop
beanomen4 Jan 6, 2023
50190e1
Lab 1: Done
beanomen4 Jan 6, 2023
32c05c4
Revert "Revert "Lab_2 + Hoffman's algorithm, which I made by hand""
beanomen4 Jan 6, 2023
82fb377
Revert "Lab_2 + Hoffman's algorithm, which I made by hand"
beanomen4 Jan 6, 2023
5972ecc
Merge pull request #65 from bldddrn/IA-03_Sharkovskyi_Volodymyr
ohorielov Jan 6, 2023
962012d
Merge pull request #56 from artbyk/IO-04_Chornyi_Artem
ohorielov Jan 6, 2023
99fb91b
Merge branch 'ohorielov:develop' into develop
beanomen4 Jan 6, 2023
0ec86d4
Merge branch 'develop' of https://github.com/beanomen4/linux_labs int…
beanomen4 Jan 6, 2023
afa2691
Revert "Revert "Lab_2 + Hoffman's algorithm, which I made by hand""
beanomen4 Jan 6, 2023
24b2862
Revert "Lab 1: Done"
beanomen4 Jan 6, 2023
7474e0e
Lab_1. Повертаю додому
beanomen4 Jan 13, 2023
6522e10
Lab_1: Fix
beanomen4 Jan 13, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Lab_1/IO-02_Kornienko_Dimas/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
CC :=cc
CFLAGS := -g -std=c99 -Wall -Werror
BUILDDIR := ../build
SRCDIR := ./

all: main

main: $(BUILDDIR)/wav_processor.o $(BUILDDIR)/main.o
$(CC) $^ -o $(BUILDDIR)/main

$(BUILDDIR)/%.o: $(SRCDIR)/%.c
$(CC) -c $(CFLAGS) -o $@ $<

clean:
rm -rf $(BUILDDIR)/*
19 changes: 19 additions & 0 deletions Lab_1/IO-02_Kornienko_Dimas/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@


#include "stdlib.h"
#include "stdio.h"
#include "wav_processor.h"

int main(void) {
wav_header *header = malloc(sizeof *header);
int16_t *data = malloc(sizeof *data);
load_wav("../Master Of Puppets.wav", header, &data);
//structure_wav(header);
adjust_wav(header, data, -0.3);
write_wav("./Master Of Puppets (-3дБ)", header, data);
adjust_wav(header, data, 0.6);
write_wav("./Master Of Puppets (+3дБ)", header, data);
free(header);
free(data);
return 0;
}
25 changes: 25 additions & 0 deletions Lab_1/IO-02_Kornienko_Dimas/wav_header.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

#ifndef WAV_HEADER_H_
#define WAV_HEADER_H_

#include "stdint.h"

typedef struct {
uint32_t chunk_id;
uint32_t chunk_size;
uint32_t format;

uint32_t subchunk1_id;
uint32_t subchunk1_size;
uint16_t audio_format;
uint16_t num_channels;
uint32_t sample_rate;
uint32_t byte_rate;
uint16_t block_align;
uint16_t bits_per_sample;

uint32_t subchunk2_id;
uint32_t subchunk2_size;
} wav_header;

#endif
74 changes: 74 additions & 0 deletions Lab_1/IO-02_Kornienko_Dimas/wav_processor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "stdlib.h"
#include "stdio.h"
#include "stdint.h"
#include "wav_processor.h"

//зчитуємо subchunk2_size у data іншу менш важливу інфу у header
void load_wav(const char *filename, wav_header *wav, int16_t **data) {
FILE *file = fopen(filename, "rb");

fread(wav, sizeof(wav_header), 1, file);

*data = malloc(wav->subchunk2_size);
fread(*data, wav->subchunk2_size, 1, file);

fclose(file);
}
//записуємо файл, спочатку header, потім data
void write_wav(const char *filename, wav_header *wav, int16_t *data) {
FILE* file = fopen(filename, "wb");

fwrite(wav, sizeof(wav_header), 1, file);
fwrite(data, wav->subchunk2_size, 1, file);

fclose(file);
}
//Вивести повну інформацію про файл
void structure_wav(wav_header *wav) {
printf("Chunk ID: %c%c%c%c\n",
wav->chunk_id & 0xFF,
(wav->chunk_id >> 8) & 0xFF,
(wav->chunk_id >> 16) & 0xFF,
(wav->chunk_id >> 24) & 0xFF);

printf("Chunk size: %u\n", wav->chunk_size);
printf("Format: %c%c%c%c\n",
wav->format & 0xFF,
(wav->format >> 8) & 0xFF,
(wav->format >> 16) & 0xFF,
(wav->format >> 24) & 0xFF);

printf("Subchunk 1 ID: %c%c%c%c\n",
wav->subchunk1_id & 0xFF,
(wav->subchunk1_id >> 8) & 0xFF,
(wav->subchunk1_id >> 16) & 0xFF,
(wav->subchunk1_id >> 24) & 0xFF);

printf("Subchunk 1 size: %u\n", wav->subchunk1_size);
printf("Audio format: %hu\n", wav->audio_format);
printf("Num channels: %hu\n", wav->num_channels);
printf("Sample rate: %u\n", wav->sample_rate);
printf("Byte rate: %u\n", wav->byte_rate);
printf("Block align: %hu\n", wav->block_align);
printf("Bits per sample: %hu\n", wav->bits_per_sample);

printf("Subchunk 2 ID: %c%c%c%c\n",
wav->subchunk2_id & 0xFF,
(wav->subchunk2_id >> 8) & 0xFF,
(wav->subchunk2_id >> 16) & 0xFF,
(wav->subchunk2_id >> 24) & 0xFF);

printf("Subchunk 2 size: %u\n", wav->subchunk2_size);
}
//За допомогою цієї функції ми можемо редагувати гучність. Переписуючи зміну data
void adjust_wav(wav_header *wav, int16_t *data, float scale) {
uint32_t samples_count = wav->subchunk2_size / sizeof(int16_t);

uint32_t i;

for(i = 0; i < samples_count; i++) {
int16_t sample = data[i];
sample += sample * scale;
data[i] = sample;
}
}
8 changes: 8 additions & 0 deletions Lab_1/IO-02_Kornienko_Dimas/wav_processor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@


#include "wav_header.h"

void load_wav(const char*, wav_header*, int16_t**);
void write_wav(const char*, wav_header*, int16_t*);
void adjust_wav(wav_header*, int16_t*, float);
void structure_wav(wav_header*);
12 changes: 12 additions & 0 deletions Lab_2/IO-02_Kornienko_Dimas/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
CC = gcc

SRCDIR := ./
SOURCES = *.c

all: main

main: $(SOURCES)
gcc $^ -o main -lm

clean:
rm -rf main *.o
16 changes: 16 additions & 0 deletions Lab_2/IO-02_Kornienko_Dimas/compressed_text.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
0000111100 001 111 01000 1100 0111 111 1100 0110 111 0101 10000 11011 111 010010 1100 0110 111 01000 1010 0101 111 10110 0001 0111 1010 001 11011 111 1100 10000 0101 0110 001 111 0001 0110 111 1100 111 0111 000010 0001 10110 10110 111 0001 0110 111 1001 1010 001 111 0000111111 010011 10000 10110 111 0000111101 1001 11010 001 1100 010010 111 1100 0110 11011 111 1010 001 111 1010 1100 11011 111 1011110 0101 0110 001
001 0001 1011110 1010 1001 101110 00001100 10110 0101 010011 11010 111 11011 1100 101110 0111 111 0110 0101 01000 111 01000 0001 1001 1010 0101 010011 1001 111 1001 1100 000010 0001 0110 1011110 111 1100 111 10110 0001 0111 1010 1000111 111 000011011 0110 111 1001 1010 001 111 10110 0001 11010 0111 1001 111 10110 0101 11010 1001 101110 111 11011 1100 101110 0111 111 1100 111 1011111 0101 101110 111 1010 1100 11011 111 1011111 001 001 0110 111 01000 0001 1001 1010 111 1010 0001 010010 1000111
000011010 010011 1001 111 1100 10110 1001 001 11010 111 10110 0101 11010 1001 101110 111 11011 1100 101110 0111 111 01000 0001 1001 1010 0101 010011 1001 111 1100 111 10110 0001 0111 1010 111 1001 1010 001 111 1011111 0101 101110 0000111001 0111 111 1000101 1100 11010 001 0110 1001 0111 111 1010 1100 11011 111 1001 0101 10000 11011 111 1010 0001 010010 111 1001 1010 1100 1001 111 1001 1010 001 111 0101 10000 11011 111 010010 1100 0110 111 01000 1100 0111
0110 0101 01000 111 11011 001 10110 0001 0110 0001 1001 001 10000 101110 111 1100 0110 11011 111 10110 0001 0110 1100 10000 10000 101110 111 0111 1100 10000 1100 0101 10001000 111 01000 1010 0001 00000 1010 111 0001 0111 111 1001 1010 001 111 01000 0101 11010 0111 1001 111 10110 0101 11010 010010 111 0101 10110 111 010011 0110 10000 010011 00000 000010 101110 10001000 111 1100 0110 11011 111 1001 1010 001 111 1011111 0101 101110 111 1010 1100 11011 111 1011110 0101 0110 001
1100 1001 111 1001 1010 001 0001 11010 111 0101 11010 11011 001 11010 0111 111 0001 0110 111 1100 0110 0101 1001 1010 001 11010 111 1011111 0101 1100 1001 111 01000 1010 0001 00000 1010 111 00000 1100 010011 1011110 1010 1001 111 1001 1010 11010 001 001 111 1011110 0101 0101 11011 111 10110 0001 0111 1010 111 1001 1010 001 111 10110 0001 11010 0111 1001 111 01000 001 001 000010 1000111 111 000011011 1001 111 010010 1100 11011 001 111 1001 1010 001
1011111 0101 101110 111 0111 1100 11011 111 1001 0101 111 0111 001 001 111 1001 1010 001 111 0101 10000 11011 111 010010 1100 0110 111 00000 0101 010010 001 111 0001 0110 111 001 1100 00000 1010 111 11011 1100 101110 111 01000 0001 1001 1010 111 1010 0001 0111 111 0111 000010 0001 10110 10110 111 001 010010 1000101 1001 101110 111 1100 0110 11011 111 1010 001 111 1100 10000 01000 1100 101110 0111 111 01000 001 0110 1001
11011 0101 01000 0110 111 1001 0101 111 1010 001 10000 1000101 111 1010 0001 010010 111 00000 1100 11010 11010 101110 111 001 0001 1001 1010 001 11010 111 1001 1010 001 111 00000 0101 0001 10000 001 11011 111 10000 0001 0110 001 0111 111 0101 11010 111 1001 1010 001 111 1011110 1100 10110 10110 111 1100 0110 11011 111 1010 1100 11010 1000101 0101 0101 0110 111 1100 0110 11011 111 1001 1010 001 111 0111 1100 0001 10000 111 1001 1010 1100 1001
01000 1100 0111 111 10110 010011 11010 10000 001 11011 111 1100 11010 0101 010011 0110 11011 111 1001 1010 001 111 010010 1100 0111 1001 1000111 111 10001001 1010 001 111 0111 1100 0001 10000 111 01000 1100 0111 111 1000101 1100 1001 00000 1010 001 11011 111 01000 0001 1001 1010 111 10110 10000 0101 010011 11010 111 0111 1100 00000 000010 0111 111 1100 0110 11011 10001000 111 10110 010011 11010 10000 001 11011 10001000 111 0001 1001 111 10000 0101 0101 000010 001 11011
10000 0001 000010 001 111 1001 1010 001 111 10110 10000 1100 1011110 111 0101 10110 111 1000101 001 11010 010010 1100 0110 001 0110 1001 111 11011 001 10110 001 1100 1001 1000111
10001001 1010 001 111 0101 10000 11011 111 010010 1100 0110 111 01000 1100 0111 111 1001 1010 0001 0110 111 1100 0110 11011 111 1011110 1100 010011 0110 1001 111 01000 0001 1001 1010 111 11011 001 001 1000101 111 01000 11010 0001 0110 000010 10000 001 0111 111 0001 0110 111 1001 1010 001 111 1011111 1100 00000 000010 111 0101 10110 111 1010 0001 0111 111 0110 001 00000 000010 1000111 111 10001001 1010 001
1011111 11010 0101 01000 0110 111 1011111 10000 0101 1001 00000 1010 001 0111 111 0101 10110 111 1001 1010 001 111 1011111 001 0110 001 00001100 0101 10000 001 0110 1001 111 0111 000010 0001 0110 111 00000 1100 0110 00000 001 11010 111 1001 1010 001 111 0111 010011 0110 111 1011111 11010 0001 0110 1011110 0111 111 10110 11010 0101 010010 111 0001 1001 0111 111 11010 001 10110 10000 001 00000 1001 0001 0101 0110 111 0101 0110 111 1001 1010 001
1001 11010 0101 1000101 0001 00000 111 0111 001 1100 111 01000 001 11010 001 111 0101 0110 111 1010 0001 0111 111 00000 1010 001 001 000010 0111 1000111 111 10001001 1010 001 111 1011111 10000 0101 1001 00000 1010 001 0111 111 11010 1100 0110 111 01000 001 10000 10000 111 11011 0101 01000 0110 111 1001 1010 001 111 0111 0001 11011 001 0111 111 0101 10110 111 1010 0001 0111 111 10110 1100 00000 001 111 1100 0110 11011 111 1010 0001 0111
1010 1100 0110 11011 0111 111 1010 1100 11011 111 1001 1010 001 111 11011 001 001 1000101 00001100 00000 11010 001 1100 0111 001 11011 111 0111 00000 1100 11010 0111 111 10110 11010 0101 010010 111 1010 1100 0110 11011 10000 0001 0110 1011110 111 1010 001 1100 00001100 101110 111 10110 0001 0111 1010 111 0101 0110 111 1001 1010 001 111 00000 0101 11010 11011 0111 1000111 111 000011010 010011 1001 111 0110 0101 0110 001 111 0101 10110
1001 1010 001 0111 001 111 0111 00000 1100 11010 0111 111 01000 001 11010 001 111 10110 11010 001 0111 1010 1000111 111 10001001 1010 001 101110 111 01000 001 11010 001 111 1100 0111 111 0101 10000 11011 111 1100 0111 111 001 11010 0101 0111 0001 0101 0110 0111 111 0001 0110 111 1100 111 10110 0001 0111 1010 10000 001 0111 0111 111 11011 001 0111 001 11010 1001 1000111
0000111110 00001100 001 11010 101110 1001 1010 0001 0110 1011110 111 1100 1011111 0101 010011 1001 111 1010 0001 010010 111 01000 1100 0111 111 0101 10000 11011 111 001 0000111000 00000 001 1000101 1001 111 1010 0001 0111 111 001 101110 001 0111 111 1100 0110 11011 111 1001 1010 001 101110 111 01000 001 11010 001 111 1001 1010 001 111 0111 1100 010010 001 111 00000 0101 10000 0101 11010 111 1100 0111 111 1001 1010 001
0111 001 1100 111 1100 0110 11011 111 01000 001 11010 001 111 00000 1010 001 001 11010 10110 010011 10000 111 1100 0110 11011 111 010011 0110 11011 001 10110 001 1100 1001 001 11011 1000111 111
Loading