Add files via upload
This commit is contained in:
parent
ae44ece4a7
commit
0a91d8ed6c
20
Makefile
Normal file
20
Makefile
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
CC=gcc
|
||||||
|
CFLAGS=-std=c2x -I./include
|
||||||
|
|
||||||
|
SRC_DIR=./src
|
||||||
|
LIB_DIR=./lib
|
||||||
|
LIB_NAME=ivafl
|
||||||
|
|
||||||
|
SRCS=$(shell find $(SRC_DIR) -name '*.c')
|
||||||
|
OBJS=$(patsubst $(SRC_DIR)/%.c,$(SRC_DIR)/%.o,$(SRCS))
|
||||||
|
|
||||||
|
all: lib$(LIB_NAME).a
|
||||||
|
|
||||||
|
lib$(LIB_NAME).a: $(OBJS)
|
||||||
|
ar rcs $@ $^
|
||||||
|
|
||||||
|
$(SRC_DIR)/%.o: $(SRC_DIR)/%.c
|
||||||
|
$(CC) $(CFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf $(OBJS) lib$(LIB_NAME).a
|
BIN
examples/wav/PinkPanther30.wav
Normal file
BIN
examples/wav/PinkPanther30.wav
Normal file
Binary file not shown.
BIN
examples/wav/a.out
Normal file
BIN
examples/wav/a.out
Normal file
Binary file not shown.
1
examples/wav/build.sh
Normal file
1
examples/wav/build.sh
Normal file
@ -0,0 +1 @@
|
|||||||
|
gcc wav_ivafl_test.c ../../libivafl.a -I../../include -O3 -std=c2x
|
52
examples/wav/wav_ivalf_test.c
Normal file
52
examples/wav/wav_ivalf_test.c
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ivafl_wav.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
int
|
||||||
|
main(int argc, char** argv)
|
||||||
|
{
|
||||||
|
printf("Testing ivafl wav library.\n");
|
||||||
|
printf("First function: ivafl_is_file_wav\n");
|
||||||
|
|
||||||
|
FILE* f = fopen("PinkPanther30.wav", "rb");
|
||||||
|
if (f == NULL)
|
||||||
|
{
|
||||||
|
printf("File doesn't exists\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
ivafl_wav_header_t* wav_header = ivafl_parse_file_into_wav_header(f);
|
||||||
|
|
||||||
|
if (ivafl_is_file_wav(wav_header) == 0)
|
||||||
|
printf("`PinkPanther30.wav` is a wav file\n");
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("`PinkPanther30.wav` isn't a wav file\n");
|
||||||
|
return EXIT_FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("riff: %.4s\n", wav_header->wav_header_info->riff_magic);
|
||||||
|
printf("bytes_sec: %u\n", wav_header->wav_header_info->bytes_sec);
|
||||||
|
printf("bytes_sec: %u\n", wav_header->wav_header_info->length_format_data);
|
||||||
|
printf("length ms: %lu\n", ivafl_wav_get_file_length_ms(wav_header));
|
||||||
|
printf("length sec: %.2f\n", ivafl_wav_get_file_length_sec(wav_header));
|
||||||
|
}
|
59
include/ivafl_alloc.h
Normal file
59
include/ivafl_alloc.h
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ivafl_ALLOC_H
|
||||||
|
#define __ivafl_ALLOC_H
|
||||||
|
|
||||||
|
#include "ivafl_platform.h"
|
||||||
|
#include "ivafl_utils.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function for reallocating memory at given pointer.
|
||||||
|
* Basically it can grow size of our allocation. If
|
||||||
|
* return equals NULL ((void*)0) then allocating
|
||||||
|
* failed
|
||||||
|
*/
|
||||||
|
void* __ivafl_realloc(const void* ptr, size_t nsize);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Easier allocating that does simple math (n * size)
|
||||||
|
* that does call malloc to allocate memory. If return
|
||||||
|
* equals NULL ((void*)0) then allocating failed
|
||||||
|
*/
|
||||||
|
void* __ivafl_calloc(int n, size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocating given amount of bytes. If return equals
|
||||||
|
* NULL ((void*)0) then allocating failed
|
||||||
|
*/
|
||||||
|
void* __ivafl_malloc(size_t size);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Free allocated memory at given pointer.
|
||||||
|
*/
|
||||||
|
void __ivafl_free(const void* ptr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Binding for memory allocation functions
|
||||||
|
*/
|
||||||
|
#define ivafl_realloc(ptr, ns) __ivafl_calloc((const void*)ptr, (size_t)ns)
|
||||||
|
#define ivafl_malloc(size) __ivafl_malloc((size_t)size)
|
||||||
|
#define ivafl_calloc(n, size) __ivafl_calloc((int)n, (size_t)size)
|
||||||
|
#define ivafl_free(ptr) __ivafl_free((const void*)ptr)
|
||||||
|
|
||||||
|
#endif /* __ivafl_ALLOC_H */
|
31
include/ivafl_log.h
Normal file
31
include/ivafl_log.h
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ivafl_LOG_H
|
||||||
|
#define __ivafl_LOG_H
|
||||||
|
|
||||||
|
#include "ivafl_platform.h"
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The ivafl_logf does print log that shows in the console.
|
||||||
|
* logs are for developer to know where's the error. ivafl_logf
|
||||||
|
* uses c format to give additional informations
|
||||||
|
*/
|
||||||
|
void ivafl_logf(const char* fmt, ...);
|
||||||
|
|
||||||
|
#endif /* __ivafl_LOG_H */
|
26
include/ivafl_platform.h
Normal file
26
include/ivafl_platform.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ivafl_PLATFORM_H
|
||||||
|
#define __ivafl_PLATFORM_H
|
||||||
|
|
||||||
|
// #if !defined(_WIN32) || !defined(__unix__) || !defined(__APPLE__) || !defined(__linux__)
|
||||||
|
// # error "You are trying to compile ivafl on not supported platform"
|
||||||
|
// #endif
|
||||||
|
|
||||||
|
#endif /* __ivafl_PLATFORM_H */
|
51
include/ivafl_utils.h
Normal file
51
include/ivafl_utils.h
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ivafl_UTILS_H
|
||||||
|
#define __ivafl_UTILS_H
|
||||||
|
|
||||||
|
typedef long unsigned int size_t;
|
||||||
|
|
||||||
|
#define ivafl_NULL ((void*)0)
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function does read given file and return
|
||||||
|
* unsigned char* (array of bytes) that then can
|
||||||
|
* be used to for example parse wav file or other
|
||||||
|
* format
|
||||||
|
*/
|
||||||
|
unsigned char* ivafl_read_bytes(const char* filename);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function does read given FILE* structure
|
||||||
|
* that need to be opened with "rb" mode. Function
|
||||||
|
* does return unsigned char* (array of bytes) that
|
||||||
|
* then can be used to for example parse wav file
|
||||||
|
* or other format
|
||||||
|
*/
|
||||||
|
unsigned char* ivafl_read_bytes_from_file(FILE* f);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_get_size_file` function does return `size_t`
|
||||||
|
* that indicates the given `FILE*` structure content length
|
||||||
|
*/
|
||||||
|
size_t ivafl_get_size_file(FILE* f);
|
||||||
|
|
||||||
|
#endif /* __ivafl_UTILS_H */
|
158
include/ivafl_wav.h
Normal file
158
include/ivafl_wav.h
Normal file
@ -0,0 +1,158 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* These pages helped me a lot while writing wav decoder and encoder
|
||||||
|
* - https://docs.fileformat.com/audio/wav/
|
||||||
|
* - http://www.topherlee.com/software/pcm-tut-wavformat.html
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef __ivafl_WAV_H
|
||||||
|
#define __ivafl_WAV_H
|
||||||
|
|
||||||
|
#include <ivafl_utils.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ----------------------
|
||||||
|
* Wav structure
|
||||||
|
* ----------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Wav Calculate macros
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define WAV_BYTES_SEC_CALCULATE(sample_rate, bits_per_sample, channels) \
|
||||||
|
(sample_rate * bits_per_sample * channels) / 8 \
|
||||||
|
|
||||||
|
#define WAV_BLOCK_ALIGN_CALCULATE(bits_per_sample, channels) \
|
||||||
|
(bits_per_sample * channels) / 8 \
|
||||||
|
|
||||||
|
/*
|
||||||
|
* WAV Channels
|
||||||
|
*/
|
||||||
|
#define WAV_MONO_CHANNLES (unsigned short)0x01
|
||||||
|
#define WAV_STEREO_CHANNELS (unsigned short)0x02
|
||||||
|
|
||||||
|
/*
|
||||||
|
* RIFF Magic is a field with which we can be 100% certain
|
||||||
|
* that file that we are reading is a wav
|
||||||
|
*/
|
||||||
|
|
||||||
|
#define __RIFF_MAGIC 'R', 'I', 'F', 'F'
|
||||||
|
#define __FORMAT_CHUNK_MAGIC 'f', 'm', 't', ' '
|
||||||
|
#define __FILE_HEADER 'W', 'A', 'V', 'E'
|
||||||
|
#define __DATA_START 'd', 'a', 't', 'a'
|
||||||
|
|
||||||
|
static const unsigned char RIFF_MAGIC[4] = { __RIFF_MAGIC };
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This header does take the most important informations about
|
||||||
|
* the wav file
|
||||||
|
*/
|
||||||
|
typedef struct ivafl_wav_header_info_t {
|
||||||
|
unsigned char riff_magic[4];
|
||||||
|
unsigned int file_size;
|
||||||
|
unsigned char file_header[4];
|
||||||
|
unsigned char format_chunk[4];
|
||||||
|
unsigned int length_format_data;
|
||||||
|
unsigned short type_format;
|
||||||
|
unsigned short channels_number;
|
||||||
|
unsigned int sample_rate;
|
||||||
|
unsigned int bytes_sec;
|
||||||
|
unsigned short block_align;
|
||||||
|
unsigned short bits_per_sample;
|
||||||
|
unsigned char data_start[4];
|
||||||
|
unsigned int data_section_length;
|
||||||
|
} ivafl_wav_header_info_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Look of a wav file
|
||||||
|
* 0 - 44 : wav header
|
||||||
|
* 44 - ... : wav data
|
||||||
|
*/
|
||||||
|
typedef struct ivafl_wav_header_t {
|
||||||
|
ivafl_wav_header_info_t* wav_header_info;
|
||||||
|
unsigned char* wav_data_section;
|
||||||
|
void* wav_allocated_bytes;
|
||||||
|
} ivafl_wav_header_t;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ----------------------
|
||||||
|
* Decode
|
||||||
|
* ----------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function `ivafl_create_wav` does create a wav structure
|
||||||
|
* that can be written to a file by `ivafl_write_wav_file`
|
||||||
|
* function
|
||||||
|
*/
|
||||||
|
ivafl_wav_header_t* ivafl_create_wav(unsigned short channels,
|
||||||
|
unsigned int sample_rate,
|
||||||
|
unsigned int bits_per_sample,
|
||||||
|
unsigned char* wav_data,
|
||||||
|
unsigned long wav_data_len);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ----------------------
|
||||||
|
* Encode
|
||||||
|
* ----------------------
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_is_file_wav` function does take one argument which
|
||||||
|
* is `FILE*` that is pointer from file structure. This function
|
||||||
|
* does take first 4 bytes and look are they are equal to `'RIFF'`
|
||||||
|
* (`RIFF_MAGIC` constant defined in `ivafl_wav.h`) which is always
|
||||||
|
* the start of WAV file. If the file is WAV then this function will
|
||||||
|
* return `0` on success and `-1` on error
|
||||||
|
*/
|
||||||
|
int ivafl_is_file_wav(ivafl_wav_header_t* wav_header);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function `ivafl_parse_file_into_wav` does take one argument which
|
||||||
|
* is `FILE*` that is pointer from file structure. Function does parse
|
||||||
|
* whole file into wav_header (`ivafl_wav_header_t` structure). Structure
|
||||||
|
* `ivafl_wav_header_t` does have every information about wav file.
|
||||||
|
*/
|
||||||
|
ivafl_wav_header_t* ivafl_parse_file_into_wav_header(FILE* f);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_wav_clean` does clean up allocated memory for `ivafl_wav_header_t*`
|
||||||
|
* structure
|
||||||
|
*/
|
||||||
|
void ivafl_wav_clean(ivafl_wav_header_t* wav_header);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_wav_get_file_length_ms` does take `ivafl_wav_header_t`
|
||||||
|
* structure which defines all informations about wav file. Function
|
||||||
|
* will return file length in miliseconds
|
||||||
|
*/
|
||||||
|
long ivafl_wav_get_file_length_ms(ivafl_wav_header_t* wav_header);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_wav_get_file_length_sec` does take `ivafl_wav_header_t`
|
||||||
|
* structure which defines all informations about wav file. Function
|
||||||
|
* will return file length in seconds
|
||||||
|
*/
|
||||||
|
double ivafl_wav_get_file_length_sec(ivafl_wav_header_t* wav_header);
|
||||||
|
|
||||||
|
#endif /* __ivafl_WAV_H */
|
17
src/avi/ivafl_avi_decode.c
Normal file
17
src/avi/ivafl_avi_decode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/avi/ivafl_avi_encode.c
Normal file
17
src/avi/ivafl_avi_encode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/bmp/ivafl_bmp_decode.c
Normal file
17
src/bmp/ivafl_bmp_decode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/bmp/ivafl_bmp_encode.c
Normal file
17
src/bmp/ivafl_bmp_encode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
77
src/ivafl_alloc.c
Normal file
77
src/ivafl_alloc.c
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ivafl_utils.h>
|
||||||
|
#include <ivafl_alloc.h>
|
||||||
|
#include <ivafl_log.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function for reallocating memory at given pointer.
|
||||||
|
* Basically it can grow size of our allocation. If
|
||||||
|
* return equals NULL ((void*)0) then allocating
|
||||||
|
* failed
|
||||||
|
*/
|
||||||
|
void*
|
||||||
|
__ivafl_realloc(const void* ptr, size_t nsize)
|
||||||
|
{
|
||||||
|
void* allocated_ptr = realloc((void*)ptr, nsize);
|
||||||
|
if (allocated_ptr == ivafl_NULL)
|
||||||
|
ivafl_logf("(__ivafl_realloc) Couldn't reallocate %lu bytes", nsize);
|
||||||
|
|
||||||
|
return allocated_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Easier allocating that does simple math (n * size)
|
||||||
|
* that does call malloc to allocate memory. If return
|
||||||
|
* equals NULL ((void*)0) then allocating failed
|
||||||
|
*/
|
||||||
|
void*
|
||||||
|
__ivafl_calloc(int n, size_t size)
|
||||||
|
{
|
||||||
|
void* allocated_ptr = calloc(n, size);
|
||||||
|
if (allocated_ptr == ivafl_NULL)
|
||||||
|
ivafl_logf("(__ivafl_calloc) Couldn't allocate %lu bytes", size);
|
||||||
|
|
||||||
|
return allocated_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Allocating given amount of bytes. If return equals
|
||||||
|
* NULL ((void*)0) then allocating failed
|
||||||
|
*/
|
||||||
|
void*
|
||||||
|
__ivafl_malloc(size_t size)
|
||||||
|
{
|
||||||
|
void* allocated_ptr = malloc(size);
|
||||||
|
if (allocated_ptr == ivafl_NULL)
|
||||||
|
ivafl_logf("(__ivafl_malloc) Couldn't allocate %lu bytes", size);
|
||||||
|
|
||||||
|
return allocated_ptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Free allocated memory at given pointer.
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
__ivafl_free(const void* ptr)
|
||||||
|
{
|
||||||
|
free((void*)ptr);
|
||||||
|
}
|
51
src/ivafl_log.c
Normal file
51
src/ivafl_log.c
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ivafl_alloc.h>
|
||||||
|
#include <ivafl_log.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The ivafl_logf does print log that shows in the console.
|
||||||
|
* logs are for developer to know where's the error. ivafl_logf
|
||||||
|
* uses c format to give additional informations
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ivafl_logf(const char* fmt, ...)
|
||||||
|
{
|
||||||
|
va_list list;
|
||||||
|
va_start(list, fmt);
|
||||||
|
|
||||||
|
// Why (strlen(fmt) * 1.5) I think this is a safe value in which
|
||||||
|
// everything can fit without any problems with overflows.
|
||||||
|
char* buf = ivafl_malloc((size_t)(strlen(fmt) * 1.5));
|
||||||
|
if (buf != NULL)
|
||||||
|
{
|
||||||
|
sprintf(buf, fmt, list);
|
||||||
|
printf("[LOG]: %s\n", buf);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
ivafl_free(buf);
|
||||||
|
va_end(list);
|
||||||
|
}
|
97
src/ivafl_utils.c
Normal file
97
src/ivafl_utils.c
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ivafl_utils.h>
|
||||||
|
#include <ivafl_alloc.h>
|
||||||
|
#include <ivafl_log.h>
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#define ivafl_DEFAULT_BYTES_FOPEN_MODE ("rb")
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function does read given file and return
|
||||||
|
* `unsigned char*` (array of bytes) that then can
|
||||||
|
* be used to for example parse wav file or other
|
||||||
|
* format
|
||||||
|
*/
|
||||||
|
unsigned char*
|
||||||
|
ivafl_read_bytes(const char* filename)
|
||||||
|
{
|
||||||
|
FILE* f = fopen(filename, ivafl_DEFAULT_BYTES_FOPEN_MODE);
|
||||||
|
if (f == ivafl_NULL)
|
||||||
|
{
|
||||||
|
ivafl_logf("(ivafl_read_bytes) Failed while opening `%s` file", filename);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned char* bytes = ivafl_read_bytes_from_file(f);
|
||||||
|
fclose(f);
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* This function does read given `FILE*` structure
|
||||||
|
* that need to be opened with `"rb"` mode. Function
|
||||||
|
* does return unsigned char* (array of bytes) that
|
||||||
|
* then can be used to for example parse wav file
|
||||||
|
* or other format
|
||||||
|
*/
|
||||||
|
unsigned char*
|
||||||
|
ivafl_read_bytes_from_file(FILE* f)
|
||||||
|
{
|
||||||
|
if (f == ivafl_NULL)
|
||||||
|
{
|
||||||
|
ivafl_logf("(ivafl_read_bytes_from_file) Failed given file is `NULL`");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t file_len = ivafl_get_size_file(f);
|
||||||
|
unsigned char* bytes = ivafl_malloc((sizeof(unsigned char) * file_len) + 1);
|
||||||
|
char curr_char = 'A';
|
||||||
|
|
||||||
|
for (size_t i = 0; i < file_len; i++)
|
||||||
|
{
|
||||||
|
curr_char = fgetc(f);
|
||||||
|
bytes[i] = curr_char;
|
||||||
|
}
|
||||||
|
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_get_size_file` function does return `size_t`
|
||||||
|
* that indicates the given `FILE*` structure content length
|
||||||
|
*/
|
||||||
|
size_t
|
||||||
|
ivafl_get_size_file(FILE* f)
|
||||||
|
{
|
||||||
|
if (f == ivafl_NULL)
|
||||||
|
{
|
||||||
|
ivafl_logf("(ivafl_get_size_file) Failed given file is `NULL`");
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
fseek(f, 0, SEEK_END);
|
||||||
|
size_t len = ftell(f);
|
||||||
|
fseek(f, 0, SEEK_SET);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
BIN
src/ivalf_log.o
Normal file
BIN
src/ivalf_log.o
Normal file
Binary file not shown.
17
src/jpeg/ivafl_jpeg_decode.c
Normal file
17
src/jpeg/ivafl_jpeg_decode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/jpeg/ivafl_jpeg_encode.c
Normal file
17
src/jpeg/ivafl_jpeg_encode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/mp3/ivafl_mp3_decode.c
Normal file
17
src/mp3/ivafl_mp3_decode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/mp3/ivafl_mp3_encode.c
Normal file
17
src/mp3/ivafl_mp3_encode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/mp4/ivafl_mp4_decode.c
Normal file
17
src/mp4/ivafl_mp4_decode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/mp4/ivafl_mp4_encode.c
Normal file
17
src/mp4/ivafl_mp4_encode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/png/ivafl_png_decode.c
Normal file
17
src/png/ivafl_png_decode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
17
src/png/ivafl_png_encode.c
Normal file
17
src/png/ivafl_png_encode.c
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
59
src/wav/ivafl_wav_decode.c
Normal file
59
src/wav/ivafl_wav_decode.c
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ivafl_wav.h>
|
||||||
|
#include <ivafl_alloc.h>
|
||||||
|
#include <ivafl_utils.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function `ivafl_create_wav` does create a wav structure
|
||||||
|
* that can be written to a file by `ivafl_write_wav_file`
|
||||||
|
* function
|
||||||
|
*/
|
||||||
|
ivafl_wav_header_t*
|
||||||
|
ivafl_create_wav(unsigned short channels,
|
||||||
|
unsigned int sample_rate,
|
||||||
|
unsigned int bits_per_sample,
|
||||||
|
unsigned char* wav_data,
|
||||||
|
unsigned long wav_data_len)
|
||||||
|
{
|
||||||
|
ivafl_wav_header_t* wav_header = (ivafl_wav_header_t*)ivafl_malloc(sizeof(ivafl_wav_header_t));
|
||||||
|
ivafl_wav_header_info_t wav_header_info = {
|
||||||
|
.riff_magic = { __RIFF_MAGIC },
|
||||||
|
.file_size = wav_data_len + sizeof(ivafl_wav_header_info_t), // I'm not sure is this a correct way
|
||||||
|
.file_header = { __FILE_HEADER },
|
||||||
|
.format_chunk = { __FORMAT_CHUNK_MAGIC },
|
||||||
|
.length_format_data = 16,
|
||||||
|
.type_format = 1,
|
||||||
|
.channels_number = channels,
|
||||||
|
.sample_rate = sample_rate,
|
||||||
|
.bytes_sec = WAV_BYTES_SEC_CALCULATE(sample_rate, bits_per_sample, channels),
|
||||||
|
.block_align = WAV_BLOCK_ALIGN_CALCULATE(bits_per_sample, channels),
|
||||||
|
.bits_per_sample = bits_per_sample,
|
||||||
|
.data_start = { __DATA_START },
|
||||||
|
.data_section_length = wav_data_len
|
||||||
|
};
|
||||||
|
|
||||||
|
wav_header->wav_header_info = &wav_header_info;
|
||||||
|
wav_header->wav_allocated_bytes = NULL;
|
||||||
|
wav_header->wav_data_section = wav_data;
|
||||||
|
|
||||||
|
return wav_header;
|
||||||
|
}
|
94
src/wav/ivafl_wav_encode.c
Normal file
94
src/wav/ivafl_wav_encode.c
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
/*
|
||||||
|
* ivafl - Image, Video, Aufio formats library
|
||||||
|
* Copyright (C) 2023 SolindekDev
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ivafl_wav.h>
|
||||||
|
#include <ivafl_alloc.h>
|
||||||
|
#include <ivafl_utils.h>
|
||||||
|
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_is_file_wav` function does take one argument which
|
||||||
|
* is `FILE*` that is pointer from file structure. This function
|
||||||
|
* does take first 4 bytes and look are they are equal to `'RIFF'`
|
||||||
|
* (`RIFF_MAGIC` constant defined in `ivafl_wav.h`) which is always
|
||||||
|
* the start of WAV file. If the file is WAV then this function will
|
||||||
|
* return `0` on success and `-1` on error
|
||||||
|
*/
|
||||||
|
int
|
||||||
|
ivafl_is_file_wav(ivafl_wav_header_t* wav_header)
|
||||||
|
{
|
||||||
|
if (memcmp(wav_header->wav_header_info->riff_magic, RIFF_MAGIC, 4) != 0)
|
||||||
|
{
|
||||||
|
// error
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// success
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Function `ivafl_parse_file_into_wav` does take one argument which
|
||||||
|
* is `FILE*` that is pointer from file structure. Function does parse
|
||||||
|
* whole file into wav_header (`ivafl_wav_header_t` structure). Structure
|
||||||
|
* `ivafl_wav_header_t` does have every information about wav file.
|
||||||
|
*/
|
||||||
|
ivafl_wav_header_t*
|
||||||
|
ivafl_parse_file_into_wav_header(FILE* f)
|
||||||
|
{
|
||||||
|
unsigned char* bytes = ivafl_read_bytes_from_file(f);
|
||||||
|
|
||||||
|
ivafl_wav_header_t* wav_header_info = (ivafl_wav_header_t*)ivafl_malloc(sizeof(ivafl_wav_header_t));
|
||||||
|
wav_header_info->wav_header_info = ((ivafl_wav_header_info_t*)bytes);
|
||||||
|
wav_header_info->wav_data_section = ((unsigned char*)(bytes + sizeof(ivafl_wav_header_info_t)));
|
||||||
|
wav_header_info->wav_allocated_bytes = ((void*)bytes);
|
||||||
|
|
||||||
|
return wav_header_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_wav_clean` does clean up allocated memory for `ivafl_wav_header_t*`
|
||||||
|
* structure
|
||||||
|
*/
|
||||||
|
void
|
||||||
|
ivafl_wav_clean(ivafl_wav_header_t* wav_header)
|
||||||
|
{
|
||||||
|
ivafl_free(wav_header->wav_allocated_bytes);
|
||||||
|
ivafl_free(wav_header);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_wav_get_file_length_ms` does take `ivafl_wav_header_t`
|
||||||
|
* structure which defines all informations about wav file. Function
|
||||||
|
* will return file length in miliseconds
|
||||||
|
*/
|
||||||
|
long ivafl_wav_get_file_length_ms(ivafl_wav_header_t* wav_header)
|
||||||
|
{
|
||||||
|
return (ivafl_wav_get_file_length_sec(wav_header)) * 1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* The `ivafl_wav_get_file_length_sec` does take `ivafl_wav_header_t`
|
||||||
|
* structure which defines all informations about wav file. Function
|
||||||
|
* will return file length in seconds
|
||||||
|
*/
|
||||||
|
double ivafl_wav_get_file_length_sec(ivafl_wav_header_t* wav_header)
|
||||||
|
{
|
||||||
|
return ((double)wav_header->wav_header_info->data_section_length / wav_header->wav_header_info->bytes_sec);
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user