-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
107 lines (82 loc) · 2.04 KB
/
Copy pathutils.cpp
File metadata and controls
107 lines (82 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @file utils.cpp
* @version 1.0
* @brief MP3enc_cpp utility functions source
* @date Mar 4, 2020
* @author Siwon Kang (kkangshawn@gmail.com)
*/
#include "utils.h"
#include <iostream>
#include <fstream>
int
Utils::read_32_bits_high_low(std::ifstream* in)
{
char bytes[4] = { 0, 0, 0, 0 };
in->read(bytes, 4);
int32_t const low = (unsigned char)bytes[3];
int32_t const midl = (unsigned char)bytes[2];
int32_t const midh = (unsigned char)bytes[1];
int32_t const high = (signed char)(bytes[0]);
return (high << 24) | (midh << 16) | (midl << 8) | low;
}
int
Utils::read_32_bits_low_high(std::ifstream* in)
{
char bytes[4] = { 0, 0, 0, 0 };
in->read(bytes, 4);
int32_t const low = (unsigned char)bytes[0];
int32_t const midl = (unsigned char)bytes[1];
int32_t const midh = (unsigned char)bytes[2];
int32_t const high = (signed char)(bytes[3]);
return (high << 24) | (midh << 16) | (midl << 8) | low;
}
int
Utils::read_16_bits_low_high(std::ifstream* in)
{
char bytes[2] = { 0, 0 };
in->read(bytes, 2);
int32_t const low = (unsigned char)bytes[0];
int32_t const high = (signed char)(bytes[1]);
return (high << 8) | low;
}
long
Utils::make_even_number_of_bytes_in_length(long x)
{
if ((x & 0x01) != 0) x++;
return x;
}
double
Utils::get_file_size(const char* file)
{
struct stat st;
if (stat(file, &st) == 0) {
return st.st_size;
}
return -1;
}
bool
Utils::is_wav(std::string file)
{
if (file.size() < 5) {
/*
* minimum length of filename will be 5 assuming that the filename
* contains the extension ".wav"
*/
return false;
}
std::string::reverse_iterator it = file.rbegin();
if (*(it + 3) == '.' &&
*(it + 2) == 'w' &&
*(it + 1) == 'a' &&
*(it) == 'v') {
return true;
}
return false;
}
int
Utils::scmp(const char* a, const char* b) {
while (*a && *b && !(*a - *b)) {
a++; b++;
}
return *a - *b;
}