Add files via upload
This commit is contained in:
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 */
|
||||
Reference in New Issue
Block a user