/*
* CINELERRA
* Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
- *
+ *
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
+ *
*/
static int read_parameter(char *string,
int *i,
- const char *title,
- char *dst_string,
- float *dst_float0,
- float *dst_float1,
+ const char *title,
+ char *dst_string,
+ float *dst_float0,
+ float *dst_float1,
float *dst_float2)
{
char *command = string + *i;
}
}
-// printf("read_parameter %d %s %s %s %s\n",
-// __LINE__,
-// title,
-// arg_text[0],
-// arg_text[1],
+// printf("read_parameter %d %s %s %s %s\n",
+// __LINE__,
+// title,
+// arg_text[0],
+// arg_text[1],
// arg_text[2]);
if(arg_text[0])
{
// Load the script to get character count
read_script();
-
+
// Set asset format
{
// Everything is timed based on speech, so render the audio for this frame.
const int debug = 0;
-
-
+
+
frame->clear_frame();
- int64_t audio_position1 = (int64_t)(file->current_frame *
+ int64_t audio_position1 = (int64_t)(file->current_frame *
asset->sample_rate /
asset->frame_rate);
- int64_t audio_position2 = (int64_t)(audio_position1 +
+ int64_t audio_position2 = (int64_t)(audio_position1 +
asset->sample_rate /
asset->frame_rate);
asset->sample_rate, audio_position1,
audio_position2);
- render_chunks(audio_position1,
+ render_chunks(audio_position1,
audio_position2 - audio_position1,
1);
if(!script) return 1;
SceneChar *speeking_character = 0;
// Sample relative to start of chunk
int64_t chunk_sample = 0;
- for(int i = 0;
- i < script->total_chunks() && current_sample < audio_position2;
+ for(int i = 0;
+ i < script->total_chunks() && current_sample < audio_position2;
i++)
{
SceneChunk *chunk = script->get_chunk(i);
int samples = chunk->audio_size / 2;
- if(audio_position1 >= current_sample &&
+ if(audio_position1 >= current_sample &&
audio_position1 < current_sample + samples)
{
speeking_character = chunk->character;
if(debug) printf("FileScene::read_frame %d\n", __LINE__);
-
+
// Render the scene.
// Store component placement in a scene graph.
SceneGraph scene;
if(debug) printf("FileScene::read_frame %d\n", __LINE__);
for(int j = 0; j < 2; j++)
{
- if(debug) printf("FileScene::read_frame %d j=%d head_order=%d body_order=%d\n",
- __LINE__,
+ if(debug) printf("FileScene::read_frame %d j=%d head_order=%d body_order=%d\n",
+ __LINE__,
j,
character->head_order,
character->body_order);
camera->at_x = asset->width / 4;
}
- character_node->x = (int)(asset->width / 2 -
+ character_node->x = (int)(asset->width / 2 -
character->w * character->scale / 2);
- character_node->y = (int)(asset->height -
+ character_node->y = (int)(asset->height -
character->h * character->scale);
break;
if(i == 0)
{
character_node->x = 0;
- character_node->y = (int)(asset->height -
+ character_node->y = (int)(asset->height -
character->h * character->scale);
if(speeking_character == character &&
speeking_character->current_camera == SceneChar::CAMERA_CU)
{
camera->at_y = character_node->y;
- camera->at_x = character_node->x +
- (character->head->x + character->head->image->get_w() / 2) * character->scale -
+ camera->at_x = character_node->x +
+ (character->head->x + character->head->image->get_w() / 2) * character->scale -
asset->width / 4;
CLAMP(camera->at_x, 0, asset->width / 2);
CLAMP(camera->at_y, 0, asset->height);
if(character->faces_left)
{
character_node->flip = 1;
- character_node->x = asset->width -
+ character_node->x = asset->width -
character->w * character->scale;
}
}
else
{
- character_node->x = (int)(asset->width -
+ character_node->x = (int)(asset->width -
character->w * character->scale);
- character_node->y = (int)(asset->height -
+ character_node->y = (int)(asset->height -
character->h * character->scale);
if(speeking_character == character &&
speeking_character->current_camera == SceneChar::CAMERA_CU)
{
- camera->at_x = character_node->x +
- character->head->x * character->scale -
+ camera->at_x = character_node->x +
+ character->head->x * character->scale -
asset->width / 4;
CLAMP(camera->at_x, 0, asset->width / 2);
}
- if(!character->faces_left)
+ if(!character->faces_left)
{
character_node->flip = 1;
character_node->x = 0;
if(i == 0)
{
character_node->x = 0;
- character_node->y = (int)(asset->height -
+ character_node->y = (int)(asset->height -
character->h * character->scale);
if(character->faces_left)
{
{
camera->at_x = asset->width / 4;
}
- character_node->x = (int)(asset->width / 2 -
+ character_node->x = (int)(asset->width / 2 -
character->w * character->scale / 2);
- character_node->y = (int)(asset->height -
+ character_node->y = (int)(asset->height -
character->h * character->scale);
if(character->faces_left)
{
{
camera->at_x = asset->width / 2;
}
- character_node->x = (int)(asset->width -
+ character_node->x = (int)(asset->width -
character->w * character->scale);
- character_node->y = (int)(asset->height -
+ character_node->y = (int)(asset->height -
character->h * character->scale);
if(!character->faces_left)
{
if(speeking_character == character)
{
//speeking_node = character_node;
-
+
int head_time = (chunk_sample / asset->sample_rate / 2) % 2;
if(head_time > 0)
double temp;
double anim_position = modf((double)chunk_sample / asset->sample_rate / 2, &temp);
double anim_length = 0.1;
-// printf("FileScene::read_frame %d %d %f\n",
-// __LINE__,
+// printf("FileScene::read_frame %d %d %f\n",
+// __LINE__,
// head_time,
// anim_position);
double intpart;
if(character->eyes.size())
{
- if(modf((file->current_frame / asset->frame_rate + script->get_char_number(character)) / 5, &intpart) <=
+ if(modf((file->current_frame / asset->frame_rate + script->get_char_number(character)) / 5, &intpart) <=
0.1 / 5 &&
file->current_frame / asset->frame_rate > 1)
{
// Render scene graph
scene.render(frame, file->cpus);
-
-
-
+
+
+
if(debug) printf("FileScene::read_frame %d\n", __LINE__);
if(script)
{
total += script->get_memory_usage();
-
+
}
//PRINT_TRACE
return total;
-void FileScene::render_chunks(int64_t start_position,
- int64_t len,
+void FileScene::render_chunks(int64_t start_position,
+ int64_t len,
int all_channels)
{
int64_t end_position = start_position + len;
src_offset, dst_offset, src_len);
// Transfer if right channel
- if(all_channels ||
+ if(all_channels ||
file->current_channel == script->get_char_number(chunk->character))
{
for(int j = 0; j < src_len; j++)
{
- audio_temp[dst_offset + j] =
- chunk->audio[(src_offset + j) * 2] |
+ audio_temp[dst_offset + j] =
+ chunk->audio[(src_offset + j) * 2] |
(chunk->audio[(src_offset + j) * 2 + 1] << 8);
}
}
}
}
if(debug) printf("FileScene::render_chunks %d\n", __LINE__);
-
-
+
+
}
void SceneChar::increment_camera()
{
current_camera++;
- if(current_camera >= CAMERA_TOTAL)
+ if(current_camera >= CAMERA_TOTAL)
current_camera = 0;
}
script->convert_path(path, model);
FILE *fd = fopen(path, "r");
-
+
// Read assets
if(fd)
while(!feof(fd))
{
char *result = fgets(string, BCTEXTLEN, fd);
-
+
if(result)
{
int len = strlen(string);
STRIP_LINE(string);
- if(debug) printf("SceneChar::read_model %d: %s\n",
- __LINE__,
+ if(debug) printf("SceneChar::read_model %d: %s\n",
+ __LINE__,
string);
-
+
for(i = 0; i < len; i++)
{
if(isalnum(string[i]))
{
string2[0] = 0;
-
+
if(read_parameter(string,
&i,
- "width:",
- 0,
- &w,
- 0,
+ "width:",
+ 0,
+ &w,
+ 0,
0))
{
}
else
if(read_parameter(string,
&i,
- "height:",
- 0,
- &h,
- 0,
+ "height:",
+ 0,
+ &h,
+ 0,
0))
{
}
else
if(read_parameter(string,
&i,
- "body:",
- string2,
- 0,
- &x,
+ "body:",
+ string2,
+ 0,
+ &x,
&y))
{
// Load image
else
if(read_parameter(string,
&i,
- "head:",
- string2,
- 0,
- &x,
+ "head:",
+ string2,
+ 0,
+ &x,
&y))
{
// Load image
else
if(read_parameter(string,
&i,
- "mouth:",
- string2,
- 0,
- &x,
+ "mouth:",
+ string2,
+ 0,
+ &x,
&y))
{
// Load image
else
if(read_parameter(string,
&i,
- "eyes:",
- string2,
- 0,
- &x,
+ "eyes:",
+ string2,
+ 0,
+ &x,
&y))
{
// Load image
else
if(read_parameter(string,
&i,
- "faces_left",
- 0,
- 0,
- 0,
+ "faces_left",
+ 0,
+ 0,
+ 0,
0))
{
faces_left = 1;
else
if(read_parameter(string,
&i,
- "scale:",
- 0,
- &scale,
- 0,
+ "scale:",
+ 0,
+ &scale,
+ 0,
0))
{
}
-
+
i = len;
}
}
}
-
+
current_line++;
}
-
+
fclose(fd);
if(debug) dump();
return 0;
}
-
+
printf("SceneChar::read_model %d: %s %s\n", __LINE__, path, strerror(errno));
return 1;
}
void SceneChar::dump()
{
- printf("SceneChar::dump %d: %p name=%s voice=%s model=%s body=%p eyes=%d mouths=%d\n",
- __LINE__,
+ printf("SceneChar::dump %d: %p name=%s voice=%s model=%s body=%p eyes=%d mouths=%d\n",
+ __LINE__,
this,
- name,
- voice,
+ name,
+ voice,
model,
body,
eyes.size(),
void SceneChunk::dump()
{
- printf("SceneChunk::dump %d: character=%s command=%d text=%s\n",
- __LINE__,
+ printf("SceneChunk::dump %d: character=%s command=%d text=%s\n",
+ __LINE__,
character->name,
command,
text);
*ptr++ = new_text[i];
}
*ptr++ = 0;
-
+
int len2 = strlen(string);
if(text)
{
char command_line[BCTEXTLEN];
char string2[MAX_CHARS];
char script_path[BCTEXTLEN];
-
+
//int total_args = 0;
if(text) len = strlen(text);
char *text_end = text + len;
{
printf("SceneChunk::render %d: no character defined.\n", __LINE__);
}
-
+
if(len > MAX_CHARS)
{
printf("SceneChunk::render %d: text '%s' exceeds festival's maximum line length of %d chars.\n",
{
ptr--;
text_ptr--;
- while(*text_ptr != ' ' &&
- *text_ptr != '\n' &&
+ while(*text_ptr != ' ' &&
+ *text_ptr != '\n' &&
text_ptr > text)
{
text_ptr--;
FILE *script_fd = fopen(script_path, "w");
#ifdef HAVE_FESTIVAL_BUILTIN
- sprintf(command_line, "%s%s --libdir %s%s -b %s",
+ sprintf(command_line, "%s%s --libdir %s%s -b %s",
script->file->exec_path, FESTIVAL_PATH,
script->file->exec_path, FESTIVAL_LIB_PATH,
script_path);
// Create script.
// The maximum text length is limited with the command line
- fprintf(script_fd,
+ fprintf(script_fd,
"(voice_%s)\n"
"(set! text (Utterance Text \"%s\"))\n"
"(utt.synth text)"
if(debug)
{
- printf("SceneChunk::render %d %s\n",
+ printf("SceneChunk::render %d %s\n",
__LINE__,
command_line);
-
+
FILE *script_fd = fopen(script_path, "r");
while(!feof(script_fd))
fputc(fgetc(script_fd), stdout);
{
int audio_start = audio_size;
-
- if(debug) printf("SceneChunk::render %d\n",
+
+ if(debug) printf("SceneChunk::render %d\n",
__LINE__);
while(!feof(fd))
{
- if(debug) printf("SceneChunk::render %d\n",
+ if(debug) printf("SceneChunk::render %d\n",
__LINE__);
if(audio_size + FREAD_SIZE > audio_allocated)
{
}
- if(debug) printf("SceneChunk::render %d audio=%p audio_size=%d\n",
+ if(debug) printf("SceneChunk::render %d audio=%p audio_size=%d\n",
__LINE__,
audio,
audio_size);
int bytes_read = fread(audio + audio_size, 1, FREAD_SIZE, fd);
- if(debug) printf("SceneChunk::render %d bytes_read=%d\n",
+ if(debug) printf("SceneChunk::render %d bytes_read=%d\n",
__LINE__,
bytes_read);
audio_size += bytes_read;
pclose(fd);
- if(debug) printf("SceneChunk::render %d audio=%p audio_size=%d audio_allocated=%d\n",
+ if(debug) printf("SceneChunk::render %d audio=%p audio_size=%d audio_allocated=%d\n",
__LINE__,
audio,
audio_size,
}
}
- memcpy(audio + audio_start,
- audio + audio_start + header_size,
+ memcpy(audio + audio_start,
+ audio + audio_start + header_size,
audio_size - audio_start - header_size);
audio_size -= header_size;
if(debug) printf("SceneChunk::render %d: audio_size=%d\n",
__LINE__,
audio_size);
}
-
+
advance_samples = audio_size / 2;
}
else
}
remove(script_path);
- if(debug) printf("SceneChunk::render %d max=%f\n",
+ if(debug) printf("SceneChunk::render %d max=%f\n",
__LINE__,
max);
}
// Truncate if ...
text_ptr = text + len - 1;
- while(text_ptr > text &&
+ while(text_ptr > text &&
(*text_ptr == ' ' ||
*text_ptr == '\n'))
text_ptr--;
if(debug) printf("SceneTokens::get_character %d %d\n",
__LINE__,
characters.size());
-
+
SceneChar *result = new SceneChar(this);
if(debug) printf("SceneTokens::get_character %d %d this=%p\n",
__LINE__,
int len = strlen(string);
STRIP_LINE(string)
- if(debug) printf("SceneTokens::read_script %d: %s\n",
- __LINE__,
+ if(debug) printf("SceneTokens::read_script %d: %s\n",
+ __LINE__,
string);
// Skip the file ID & empty lines
{
strcpy(char_name, string);
- if(debug) printf("SceneTokens::read_script %d: char_name=%s\n",
- __LINE__,
+ if(debug) printf("SceneTokens::read_script %d: char_name=%s\n",
+ __LINE__,
char_name);
current_char = get_character(char_name);
- if(debug) printf("SceneTokens::read_script %d current_char=%p\n",
- __LINE__,
+ if(debug) printf("SceneTokens::read_script %d current_char=%p\n",
+ __LINE__,
current_char);
// Reset the current chunk pointer
{
if(!current_char)
{
- printf("SceneTokens::read_script %d Line %d: dialogue text but no current character\n",
+ printf("SceneTokens::read_script %d Line %d: dialogue text but no current character\n",
__LINE__,
current_line);
}
// Append dialogue to current chunk
current_chunk->append_text(string + i);
}
-
+
i = len;
}
}
}
}
}
-
-
-
+
+
+
fclose(fd);
- if(debug) printf("SceneTokens::read_script %d total_chunks=%d\n",
+ if(debug) printf("SceneTokens::read_script %d total_chunks=%d\n",
__LINE__,
total_chunks());
// Parse commands in dialogue
SceneChunk *new_chunk = new SceneChunk(this);
new_chunk->character = chunk->character;
chunks.insert(new_chunk, i + 1);
-
+
// Move text from start of command to new chunk.
new_chunk->append_text(ptr);
// Truncate current chunk
if(debug) printf("SceneTokens::read_script %d\n", __LINE__);
// Read command
- while(ptr < end &&
- (*ptr == '[' || *ptr == ' ' || *ptr == '\n'))
+ while(ptr < end &&
+ (*ptr == '[' || *ptr == ' ' || *ptr == '\n'))
ptr++;
if(debug) printf("SceneTokens::read_script %d\n", __LINE__);
char *ptr2 = string;
char *string_end = string + BCTEXTLEN;
- while(*ptr != ']' &&
+ while(*ptr != ']' &&
*ptr != ' ' &&
*ptr != '\n' &&
- ptr < end &&
+ ptr < end &&
ptr2 < string_end - 1)
{
*ptr2++ = *ptr++;
else
{
// TODO: line numbers
- printf("SceneTokens::read_script %d: Unknown command '%s'\n",
- __LINE__,
+ printf("SceneTokens::read_script %d: Unknown command '%s'\n",
+ __LINE__,
string);
}
if(debug) printf("SceneTokens::read_script %d\n", __LINE__);
// Search for more text
- while(ptr < end &&
- (*ptr == ']' || *ptr == ' ' || *ptr == '\n'))
+ while(ptr < end &&
+ (*ptr == ']' || *ptr == ' ' || *ptr == '\n'))
ptr++;
// Create new chunk for rest of text
}
}
}
-
-
+
+
if(debug) dump();
return 0;
}
FileSystem fs;
fs.extract_dir(dst, path);
strcat(dst, src);
-
+
struct stat ostat;
if(stat(dst, &ostat))
{
if(!BC_CModels::has_alpha(result->get_color_model()) )
- printf("SceneTokens::load_image %d: image %s has no alpha channel\n",
+ printf("SceneTokens::load_image %d: image %s has no alpha channel\n",
__LINE__,
path);
return result;
{
background_image = load_image(background);
}
-
+
if(background_image)
{
SceneNode *node = new SceneNode("background");
characters.get(i)->dump();
}
-
+
for(int i = 0; i < chunks.size(); i++)
{
chunks.get(i)->dump();